user995009
user995009

Reputation:

JBoss 6 DataSource JNDI Not Found

I am trying to deploy .war file on JBoss 6 and I have made MySql datasource which I want to access using JNDI.

My Config looks like this :

in myDB-mysql-ds.xml

jndi-name : MyDataSource
in jboss-web.xml
res-ref-name : jdbc/MyDataSource
res-type : javax.sql.DataSource
jndi-name : java:/MyDataSource

in applicationContext.xml

property name="jndiName"
& its value : java:comp/env/jdbc/MyDataSource

When I deploy this war file, It gets bound to MyDatasource like,

INFO  [ConnectionFactoryBindingService] Bound ConnectionManager 'jboss.jca:service=DataSourceBinding,name=MyDataSource' to JNDI name 'java:MyDataSource'

but still I get error :

ERROR [[/AppName]] Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: JNDI object with [java:comp/env/jdbc/MyDataSource] not found: JNDI implementation returned null

Upvotes: 1

Views: 3884

Answers (1)

gprathour
gprathour

Reputation: 15333

It is because you are accessing it some wrong way. You should do the following,

<use-java-context>false</use-java-context>

and then access it by its JNDI name.

Upvotes: 0

Related Questions