JNDI in spring MVC - spring-mvc

Can someone please tell me how to configure JNDI name in SPRING MVC? I am using jboss version7.1.1 and DB is oracle 11g. I have defined the JNDI in jBoss server. How to mention the JNDI name in spring-servlet.xml? I have tried many options its not working. I am keep getting Name Not found exception.

<jee:jndi-lookup id="dataSource"
jndi-name="java:jboss/datasources/ExampleDS"
expected-type="javax.sql.DataSource" />
Where the value of jndi-name matches what you have configured in JBoss. You need to register jee namespace something like this:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd">

Related

Spring component scan error(schema_reference.4: Failed to read schema document 'https://www.springframework.org/schema/beans/spring-beans-4.3.xsd')

I have created a simple dynamic project without maven in eclipse. Only when I use tag context:component-scan, I face below error in Spring dispatcher file :-
schema_reference.4: Failed to read schema document 'https://www.springframework.org/schema/beans/spring-beans-4.3.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root
element of the document is not .
Not sure from where version 4.3 is refered. I am using spring version 5.0.0.RELEASE and have added all jars in lib. Below is the content of spring dispatcher file :-
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package="com.example.controller"/>
</beans>
I cant find fix for this issue. Suitable help will be appreciated.
There are many possibilities for this problem.
Initially you added ..../spring-beans-4.3.xsd and then you removed the version but error is still showing. It is because eclipse is reading from cache. Try removing cache in prefences->General->Network->cache
Even if you project is not maven, right click on the project go to properties and add "Maven Dependencies" in your Build Path. This resolved the similar error for me once.
If the above two does not work for you, try copy pasting this code
<?xml version="1.0" encoding="utf-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:ctx="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd ">
<ctx:annotation-config></ctx:annotation-config>
<ctx:component-scan base-package="com.*"></ctx:component-scan>

Unable to locate Spring NamespaceHandler for XML schema namespace in OSGi (Karaf) with Web Application Bundle

I am trying to deploy the Web Application Bundle in karaf, but somehow Unable to locate Spring NamespaceHandler for XML schema namespace even after proper schema.
What could be the issue?
Karaf version : 3.0.0
Spring version : 3.2.x
Jetty version : 8.x
More details below:
Error while deploying:
org.springframework.beans.factory.parsing.BeanDefinitionParsingException:
Configuration problem: Unable to locate Spring NamespaceHandler for XML schema
namespace [http://www.springframework.org/schema/mvc]
Context class
<context-param>
<param-name>contextClass</param-name>
<param-value>org.springframework.osgi.web.context.support.OsgiBundleXmlWebApplicationContext</param-value>
</context-param>
Context file:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<mvc:resources mapping="/mydcos/**" location="file:/opt/mydocs/css/" />
Make sure you have spring-webmvc installed in Karaf. Spring DM is kinda legacy but MVC namespace handler is registered in same way as rest of them.

Error while running spring mvc as standalone app using embedded jetty

I have a main class to run spring mvc application as standalone application using jetty. I used maven-shade-plugin to generate the jar file.
I see the following error when i run the jar file
org.eclipse.jetty.servlet.ServletHolder$1: org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 8 in XML document from ServletContext resource [/WEB-INF/mvc-dispatcher-servlet.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 8; columnNumber: 106; cvc-elt.1: Cannot find the declaration of element 'beans'.
My mvc-dispacher-servlet.xml looks like below
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">
Can any one help me what is missing
It worked by adding the below in maven-shade-plugin configuration
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.handlers</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.schemas</resource>
</transformer>

Override Spring Data Elastic Search cluster node configuration

I'm using Elastic Search for my project activities in which I communicated to the backend ES cluster through the spring utility
spring-data-elastic-search
Following are the spring-repository descriptions for the webapp.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:elasticsearch="http://www.springframework.org/schema/data/elasticsearch"
xsi:schemaLocation="http://www.springframework.org/schema/data/elasticsearch http://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch-1.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
<elasticsearch:transport-client id="client" cluster-nodes="localhost:9300" />
<bean name="elasticsearchTemplate"
class="org.springframework.data.elasticsearch.core.ElasticsearchTemplate">
<constructor-arg name="client" ref="client" />
</bean>
<elasticsearch:repositories
base-package="com.customer.repositories" />
</beans>
Here I've specified the cluster node configuration as cluster-nodes="localhost:9300" and it is working fine with my local testing.
In production server we've a full functional cluster setup with host IP say (192.xx.xx.xx). So my problem is that, we have specified the cluster host in a yml file in /etc/project/es.yml file in the production server. So I need to tweak my application to take the cluster configuration from this custom location.
Since the above spring-repository xml initialized by the spring container, we are unable to override the behaviour. Is there any way to achieve it with spring-data-elastic-search ?
Finally I resolved my issue and sharing it here, so that it may be useful to some one else.
Changed YML idea to property file (es.props)
spring repository descriptions should be as follows
<?xml version="1.0" encoding="UTF-8"?>co
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:elasticsearch="http://www.springframework.org/schema/data/elasticsearch"
xsi:schemaLocation="http://www.springframework.org/schema/data/elasticsearch
http://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch-1.0.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd">
<context:property-placeholder location="file:/etc/project/es.props" />
<elasticsearch:transport-client id="client" cluster-nodes="${es-host}:9300""/>
<bean name="elasticsearchTemplate"
class="org.springframework.data.elasticsearch.core.ElasticsearchTemplate">
<constructor-arg name="client" ref="client" />
</bean>
<elasticsearch:repositories
base-package="com.customer.repositories" />
</beans>
Which used Spring PropertySourcePlaceHolder modification mechanism in 3.1+.
So it will look up for es.host in /etc/project/es.props. Local testers can override this property by starting the server with -Des.host=custom-cluser-host
Actually Mohsin(Spring-data-elastic-search developer) gave hints to arrive at this solution. Thanks Mohsin.

Encryption Transformer in Mule

Please can anyone help me with encryption namespace and schema location in Mule 3.4.
I have this Configuration XML
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd">
<encryption:config name="Encryption_PGP" defaultEncrypter="PGP_ENCRYPTER" doc:name="Encryption_PGP">
<encryption:pgp-encrypter-config publicKeyRingFileName="./mule.gpg" secretKeyRingFileName="./secring.gpg" secretAliasId="3879972755627455806" secretPassphrase="mule1234" principal="test1"/>
</encryption:config>
<flow name="sdsd">
<encryption:encrypt config-ref="Encryption_PGP" doc:name="Encryption" using="PGP_ENCRYPTER" input-ref="#[message.payload]">
<encryption:pgp-encrypter principal="fernando.martinez <fernando.martinez#mulesoft.com>" />
</encryption:encrypt>
</flow>
</mule>
But its giving me this error: The prefix "encryption" for element "encryption:config" is not bound.
To use the the message processors from the encryption namespace you need to install the Anypoint Enterprise Security module
You can find more informations about how to use it here
That said this is an EE only feature, so if you don't have an EE license you should probably use the PGP security instead

Resources