Java 无法在JBoss 7.1中获取JNDI数据源
我试图从JBoss 7.1中获取一个数据源的引用,但是我一直得到下面的异常跟踪Java 无法在JBoss 7.1中获取JNDI数据源,java,jboss7.x,datasource,jndi,Java,Jboss7.x,Datasource,Jndi,我试图从JBoss 7.1中获取一个数据源的引用,但是我一直得到下面的异常跟踪 javax.naming.NameNotFoundException: SpecOpsDB -- service jboss.naming.context.java.jboss.exported.SpecOpsDB at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:97) at org.
javax.naming.NameNotFoundException: SpecOpsDB -- service jboss.naming.context.java.jboss.exported.SpecOpsDB
at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:97)
at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:177)
at org.jboss.naming.remote.protocol.v1.Protocol$1.handleServerMessage(Protocol.java:124)
at org.jboss.naming.remote.protocol.v1.RemoteNamingServerV1$MessageReciever$1.run(RemoteNamingServerV1.java:70)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
现在使用的配置如下所示:
standalone.xml
Jboss控制台日志显示数据源已绑定
11:01:09,105 INFO [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-4) JBAS010400: Bound data source [java:/SpecOpsDB]
我甚至在JBoss控制台UI上进行了测试,测试结果良好
我遗漏了哪些要点?您是想从服务器内部还是外部进行此查找?是的,它来自独立的java main方法。如果我在servlet中运行类似的代码(没有properties对象),它工作得非常好。您的类路径中需要jboss jndi客户端JAR。感谢您的输入,您能指出哪些JAR吗??此外,如果缺少jar,是否应该存在ClassNotFoundException???请尝试JBOSS_HOME/bin/client/JBOSS-client-7.1.x.Final.jar。
<module xmlns="urn:jboss:module:1.0" name="com.mysql">
<resources>
<resource-root path="mysql-connector-java-5.1.34-bin.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
</dependencies>
</module>
DataSource jBossDataSource = null;
try {
Properties props = new Properties();
props.put(Context.INITIAL_CONTEXT_FACTORY,
"org.jboss.naming.remote.client.InitialContextFactory");
props.put(Context.PROVIDER_URL, "remote://localhost:4447");
props.put(Context.SECURITY_PRINCIPAL, "admin");
props.put(Context.SECURITY_CREDENTIALS, "password");
Context ctxt = new javax.naming.InitialContext(props);
log.debug("Context Initialized");
Object lookup = ctxt.lookup("java:/SpecOpsDB");
jBossDataSource = (javax.sql.DataSource) lookup;
log.info("Got JBoss DataSource");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
11:01:09,105 INFO [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-4) JBAS010400: Bound data source [java:/SpecOpsDB]