`
wuhongyu
  • 浏览: 409754 次
  • 性别: Icon_minigender_1
  • 来自: 哈尔滨
社区版块
存档分类
最新评论

javax.naming.NameNotFoundException: mysql_ds not bound

阅读更多

前天单位招外包,让我给出点题,然后跟两个老大哥去面试一下,说实话,我还想出去参加面试呢,现在这点工资,实在是难以糊口啊!出了两道上机题,一个EJB的,一个struts2的,题很简单,结果面了五个人,没一个完成的,领导很郁闷,我也很无奈。刚才想用给考生配的环境玩点东西,结果发现当时数据源配的居然有点问题,我晕啊,还好不影响那两道上机题,不然丢人可就丢大了。

 

问题 是这样:我用jboss docs中mysql数据源的模板配了一个数据源,当调用的时候报如下错误

 

javax.naming.NameNotFoundException: mysql_ds not bound
	at org.jnp.server.NamingServer.getBinding(NamingServer.java:771)
	at org.jnp.server.NamingServer.getBinding(NamingServer.java:779)
	at org.jnp.server.NamingServer.getObject(NamingServer.java:785)
	at org.jnp.server.NamingServer.lookup(NamingServer.java:443)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
	at sun.rmi.transport.Transport$1.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at sun.rmi.transport.Transport.serviceCall(Unknown Source)
	at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
	at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(Unknown Source)
	at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)
	at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Unknown Source)
	at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)
	at sun.rmi.server.UnicastRef.invoke(Unknown Source)
	at org.jnp.server.NamingServer_Stub.lookup(Unknown Source)
	at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:726)
	at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:686)
	at javax.naming.InitialContext.lookup(Unknown Source)
	at test.Test.main(Test.java:44)
 

在jboss的控制台中可以看到这个JNDI

 

 

原因 :在配置mysql数据源时,没有指定<use-java-context>属性,因此无法在jboss的JVM外VM中找到这个数据源。可以到http://community.jboss.org/wiki/ConfigDataSources 查看关于这个配置的说明。这个属性的默认值为true,也就是说,如果你想在jboss的JVM以外访问这个数据源,需要手动将该值改为false。

 

 

解决 :在数据源配置文件中(我的是mysql-ds.xml),加入<use-java-context>false</use-java-context>,就可以得到这个数据源了。如:

<datasources>
  <local-tx-datasource>
    <jndi-name>mysql_ds</jndi-name>
    <use-java-context>false</use-java-context>


    <connection-url>jdbc:mysql://127.0.0.1:3306/exam</connection-url>
    <driver-class>com.mysql.jdbc.Driver</driver-class>
    <user-name>root</user-name>
    <password>wuhongyu1985</password>
    <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name>
    <metadata>
       <type-mapping>mySQL</type-mapping>
    </metadata>
  </local-tx-datasource>
</datasources>
 

 

 

 

 

 

 

 

分享到:
评论

相关推荐

    Javax.naming.NameNotFoundException

    在IT行业中,我们经常遇到各种异常,其中之一是“Javax.naming.NameNotFoundException”。这个异常通常在Java命名和目录接口(JNDI)中出现,当我们尝试查找一个在命名上下文中不存在的名称时,就会抛出这个异常。...

    数据池连接Name jdbc is not bound in this Context解决方案

    在这个问题中,开发者遇到了一个常见的错误:“Name jdbc is not bound in this Context”,这通常意味着在Tomcat的环境中,指定的数据源没有被正确地绑定或配置。 要解决这个问题,首先需要在Tomcat的配置文件中...

    jsp连接MySQL用连接池方式步骤

    1. **javax.naming.NameNotFoundException**:如果出现“Name not bound in this context”错误,确保`context.xml`中的`name`属性与`web.xml`中的`res-ref-name`属性完全一致。 2. **javax.naming....

    struts2开发遇到的问题

    6. **ERROR:javax.naming.NameNotFoundException: Name jdbc is not bound in this Context** 这个错误表明在当前环境中找不到指定的JDBC名称。需要检查并修正`server.xml`中的JNDI名称。 7. **严重:Exception ...

    关于tomcat和mysql连接池问题的详解.docx

    问题二:javax.naming.NameNotFoundException: Name XXX is not bound in this Context 这个问题表明在当前上下文中找不到名为XXX的数据源。这可能是由于Tomcat 5.5及以上版本中,`factory`属性值的更新导致的。原始...

Global site tag (gtag.js) - Google Analytics