I want to make DataSource
in Spring
through JNDI. All the configuration are given.
Can someone tell me what is wrong with the configuration.
One thing I would like to mention here is that JNDI DS is hosted on JBoss server which does not host the Spring
application.
Configuration
datasource-ds.xml
<?xml version="1.0" encoding="UTF-8"?>
<datasources>
<local-tx-datasource>
<jndi-name>jdbc/wc-mysql</jndi-name>
<connection-url>jdbc:mysql://xx.xx.xx.xx:3306/club</connection-url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<user-name>club</user-name>
<password>club</password>
<exception-sorter-class-name>
org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter
</exception-sorter-class-name>
<min-pool-size>5</min-pool-size>
<max-pool-size>20</max-pool-size>
<use-java-context>false</use-java-context>
<metadata><type-mapping>mySQL</type-mapping></metadata>
</local-tx-datasource>
</datasources>
configContext.xml
<bean id="wcDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="jdbc/wc-mysql" />
<property name="jndiEnvironment">
<props>
<prop key="java.naming.provider.url">jnp://yy.yy.yy.yy:1099</prop>
<!--
<prop key="java.naming.factory.initial">
org.springframework.mock.jndi.SimpleNamingContextBuilder
</prop>
<prop key="java.naming.factory.url.pkgs">yourPackagePrefixesGoHere</prop> -->
<!-- other key=values here -->
</props>
</property>
<!-- other properties here-->
</bean>
Exception
Caused by: javax.naming.NameNotFoundException: Name jdbc is not bound in this Context
at org.apache.naming.NamingContext.lookup(NamingContext.java:770)
at org.apache.naming.NamingContext.lookup(NamingContext.java:153)
at org.apache.naming.SelectorContext.lookup(SelectorContext.java:152)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:154)
Best Answer
I have made few changes and Its now working fine.
A JNDI Template must be initialized with the JNP properties. And URL to JBoss server has to be in that properties.
configContext.xml
But after doing that changes I was facing an exception
So I found a link mentioning to include a dependency of
jbossall-client.jar
in the POM to resolve the issue. So the pom changes areEvery thing seems to be working fine.
Thanks.