未找到 JBoss 6 数据源 JNDI
我正在尝试在 JBoss 6 上部署 .war 文件,并且我已经制作了 MySql 数据源,我想使用 JNDI 访问它。
我的配置看起来像这样:
在 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
当我部署这个 war 文件时,它会像绑定到 MyDatasource 一样,
INFO [ConnectionFactoryBindingService] Bound ConnectionManager 'jboss.jca:service=DataSourceBinding,name=MyDataSource' to JNDI name 'java:MyDataSource'
但我仍然得到错误 :
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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是因为您以错误的方式访问它。您应该执行以下操作:
,然后通过其
JNDI 名称
访问它。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
.