在查找jdbc数据源的JNDI连接时,我遇到以下错误:
javax。命名。ConfigurationException:无法完成“java:”名称上的JNDI操作,因为服务器运行时无法将该操作的线程与任何J2EE应用程序组件关联。当使用“java:”名称的JNDI客户端未在服务器应用程序请求的线程上执行时,可能会出现这种情况。确保J2EE应用程序不会在静态代码块或该J2EE应用程序创建的线程中对“java:”名称执行JNDI操作。这样的代码不一定在服务器应用程序请求的线程上运行,因此在“java:”名称上的JNDI操作不支持这些代码。[根异常是javax.naming.NameNotFoundException:在上下文“java:”中找不到名称。]
我的查找代码在一个静态方法中。这就是这个错误的原因。我没有创建任何线程
它在tomcat中工作没有任何问题
多谢你的帮忙
我使用的代码如下:
javax.naming.InitialContext ctx = new javax.naming.InitialContext();
Context cxt = (Context) ctx.lookup("java:/comp/env/");
Stacktrace:
C1APP522 2 2013-07-01 21:57:18,332 ERROR DBUtil get EnvContext failed
javax.naming.ConfigurationException: A JNDI operation on a "java:" name cannot be completed because the server runtime is not able to associate the operation's thread with any J2EE application component. This condition can occur when the JNDI client using the "java:" name is not executed on the thread of a server application request. Make sure that a J2EE application does not execute JNDI operations on "java:" names within static code blocks or in threads created by that J2EE application. Such code does not necessarily run on the thread of a server application request and therefore is not supported by JNDI operations on "java:" names. [Root exception is javax.naming.NameNotFoundException: Name not found in context "java:".]
at com.ibm.ws.naming.java.javaURLContextImpl.throwConfigurationExceptionWithDefaultJavaNS(javaURLContextImpl.java:428)
at com.ibm.ws.naming.java.javaURLContextImpl.lookup(javaURLContextImpl.java:399)
at com.ibm.ws.naming.java.javaURLContextRoot.lookup(javaURLContextRoot.java:220)
at com.ibm.ws.naming.java.javaURLContextRoot.lookup(javaURLContextRoot.java:160)
at javax.naming.InitialContext.lookup(InitialContext.java:436)
at com.test.integration.database.DBUtil_Ext.getEnvContext(DBUtil_Ext.java:121)
at com.test.integration.database.DBUtil_Ext.getDataSource(DBUtil_Ext.java:102)
at com.test.integration.database.DBUtil_Ext.getConnection(DBUtil_Ext.java:70)
at com.test.integration.IntegrationTransportPlugin_Ext.send(IntegrationTransportPlugin_Ext.java:107)
at com.test.integration.IntegrationTransportPlugin_Ext.send(IntegrationTransportPlugin_Ext.gs)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:611)
at com.test.system.integration.plugins.PluginProxy.invoke(PluginProxy.java:66)
at $Proxy58.send(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:611)
at com.test.system.integration.plugins.PluginCallTraceImpl$PluginCallTraceHandler.invoke(PluginCallTraceImpl.java:61)
at $Proxy58.send(Unknown Source)
at com.test.system.integration.messaging.dispatch.MessageWriter$2.run(MessageWriter.java:347)
at com.test.system.transaction.ScopedUserTransaction.run(ScopedUserTransaction.java:54)
at com.test.system.transaction.TransactionManagerImpl.execute(TransactionManagerImpl.java:111)
at com.test.system.integration.messaging.dispatch.AckHelper.executeMessageOperation(AckHelper.java:137)
at com.test.system.integration.messaging.dispatch.AckHelper.executeMessageOperation(AckHelper.java:121)
at com.test.system.integration.messaging.dispatch.MessageWriter.executeSendAndAfterSendInTxn(MessageWriter.java:332)
at com.test.system.integration.messaging.dispatch.MessageWriter.sendNextMessage(MessageWriter.java:272)
at com.test.system.integration.messaging.dispatch.MessageSenderRunnable.trySendMessage(MessageSenderRunnable.java:52)
at com.test.system.integration.messaging.dispatch.MessageSenderRunnable.send(MessageSenderRunnable.java:42)
at com.test.system.integration.messaging.dispatch.MessageSenderRunnable.run(MessageSenderRunnable.java:30)
at com.test.system.integration.messaging.dispatch.MessageWriter$CatchesExceptionRunnable.run(MessageWriter.java:603)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:452)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:314)
at java.util.concurrent.FutureTask.run(FutureTask.java:149)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:897)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:919)
at java.lang.Thread.run(Thread.java:736)
Caused by: javax.naming.NameNotFoundException: Name not found in context "java:".
at com.ibm.ws.naming.ipbase.NameSpace.getParentCtxInternal(NameSpace.java:1837)
at com.ibm.ws.naming.ipbase.NameSpace.lookupInternal(NameSpace.java:1166)
at com.ibm.ws.naming.ipbase.NameSpace.lookup(NameSpace.java:1095)
at com.ibm.ws.naming.urlbase.UrlContextImpl.lookup(UrlContextImpl.java:1233)
at com.ibm.ws.naming.java.javaURLContextImpl.lookup(javaURLContextImpl.java:395)
... 37 more
C1APP522 2013-07-01 21:57:18,332 ERROR Messaging Exception in MessageSenderRunnable
java.lang.RuntimeException: get EnvContext failed
at com.test.integration.database.DBUtil_Ext.getEnvContext(DBUtil_Ext.java:125)
at com.test.integration.database.DBUtil_Ext.getDataSource(DBUtil_Ext.java:102)
at com.test.integration.database.DBUtil_Ext.getConnection(DBUtil_Ext.java:70)
at com.test.integration.IntegrationTransportPlugin_Ext.send(IntegrationTransportPlugin_Ext.java:107)
at com.test.integration.IntegrationTransportPlugin_Ext.send(IntegrationTransportPlugin_Ext.java)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:611)
at com.test.system.integration.plugins.PluginProxy.invoke(PluginProxy.java:66)
at $Proxy58.send(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:611)
at com.test.system.integration.plugins.PluginCallTraceImpl$PluginCallTraceHandler.invoke(PluginCallTraceImpl.java:61)
at $Proxy58.send(Unknown Source)
at com.test.system.integration.messaging.dispatch.MessageWriter$2.run(MessageWriter.java:347)
at com.test.system.transaction.ScopedUserTransaction.run(ScopedUserTransaction.java:54)
at com.test.system.transaction.TransactionManagerImpl.execute(TransactionManagerImpl.java:111)
at com.test.system.integration.messaging.dispatch.AckHelper.executeMessageOperation(AckHelper.java:137)
at com.test.system.integration.messaging.dispatch.AckHelper.executeMessageOperation(AckHelper.java:121)
at com.test.system.integration.messaging.dispatch.MessageWriter.executeSendAndAfterSendInTxn(MessageWriter.java:332)
at com.test.system.integration.messaging.dispatch.MessageWriter.sendNextMessage(MessageWriter.java:272)
at com.test.system.integration.messaging.dispatch.MessageSenderRunnable.trySendMessage(MessageSenderRunnable.java:52)
at com.test.system.integration.messaging.dispatch.MessageSenderRunnable.send(MessageSenderRunnable.java:42)
at com.test.system.integration.messaging.dispatch.MessageSenderRunnable.run(MessageSenderRunnable.java:30)
at com.test.system.integration.messaging.dispatch.MessageWriter$CatchesExceptionRunnable.run(MessageWriter.java:603)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:452)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:314)
at java.util.concurrent.FutureTask.run(FutureTask.java:149)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:897)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:919)
at java.lang.Thread.run(Thread.java:736)
假设数据源已配置为WAS,则有两个选项:
A.在部署期间,将数据源绑定到调用组件的命名空间中,并使用以“java: comp/env/”开头的名称进行查找。例如,要绑定整个Web应用程序的数据源,您应该将以下内容添加到web.xml:
<resource-ref>
<res-ref-name>name_used_in_lookup</res-ref-name>
<jndi-name>data_source_jndi_name</jndi-name>
</resource-ref>
name_used_in_lookup应该没有java: comp/env/部分。
b、 直接按数据源的JNDI名称查找数据源,而不使用“java:comp/env/”
如果有人能帮助我纠正代码中的问题,我将不胜感激。不知道我哪里错了。 当前我的persistence.xml包含
问题内容: 我有一个表,带有2个重要列DocEntry,WebId 样本数据就像 现在我们可以在这里注意到,在WebId列中缺少S004。我们如何通过查询找到这些缺失的数字。 进一步说明: 如果网站ID之间缺少任何数字,则Web ID应按升序排列,例如S001,S002,S003,S004,S005。我没有任何单独的表格来输入可能的条目,因为这是不切实际的。我必须逐月查找丢失的数字,以每个月的开始
我对que的查找失败了。que在wildfly中注册,并使用IronJacamar.xml进行配置 启动时的wildfly输出: ironjacamar配置: ra.xml: 我的例外:
在使用资源引用从服务器上下文获取数据源连接时,我收到了JNDI查找错误。请注意,如果我不使用,则“查找”是有效的。 javax。命名。ConfigurationException:无法完成“java:”名称上的JNDI操作,因为服务器运行时无法将该操作的线程与任何J2EE应用程序组件关联。当使用“java:”名称的JNDI客户端未在服务器应用程序请求的线程上执行时,可能会出现这种情况。确保J2EE
问题:似乎无法通过spring在Webphsere服务器中执行jndi查找EJB3。一直找不到我的jndi名称。我看不出我做错了什么。对于Websphere,您是否必须为jndi名称查找添加不同的内容? 堆栈溢出参考问题-EJB3注入Springbean 版本: Spring版本:4.1.2 WebSphereServer版本:7.0.0.27 Spring错误: 创建名为'myLocalEjb'
我是java EE的新手。最近我正在使用bean无状态处理一个项目,但我得到了以下错误 豆子: Servlet: javax.name.nameingException: 在 SerialContext[myEnv={java.name.factory.initial=com.sun.enterprise.name.name.impl.SerialInitContext, java.name.fa