从Java类加载配置时,我遇到nameNotFoundException问题。我在wildfly中添加了数据源,并成功创建了连接。但是,当我要从Java类访问时,它会抛出错误。下面是错误堆栈跟踪
Caused by: javax.naming.NameNotFoundException: env/jdbc/dsMETASCAN1 -- service jboss.naming.context.java.module.InfoExService.InfoExService.env.jdbc.dsMETASCAN1
at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:104)
at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:202)
at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:179)
at org.jboss.as.naming.InitialContext$DefaultInitialContext.lookup(InitialContext.java:235)
at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:188)
at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:184)
at javax.naming.InitialContext.lookup(InitialContext.java:411) [rt.jar:1.7.0_80]
at javax.naming.InitialContext.lookup(InitialContext.java:411) [rt.jar:1.7.0_80]
at org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:154) [spring-context-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:87) [spring-context-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:152) [spring-context-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:178) [spring-context-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:95) [spring-context-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.java:105) [spring-context-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.jndi.JndiObjectFactoryBean.lookupWithFallback(JndiObjectFactoryBean.java:201) [spring-context-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.jndi.JndiObjectFactoryBean.afterPropertiesSet(JndiObjectFactoryBean.java:187) [spring-context-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1547) [spring-beans-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1485) [spring-beans-3.2.2.RELEASE.jar:3.2.2.RELEASE]
... 89 more
Context.xml
<ResourceLink global="jdbc/dsMETASCAN1" name="jdbc/dsMETASCAN1"
type="javax.sql.DataSource" />
在Spring配置中,我们像这样加载
<bean id="ds" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/env/jdbc/dsMETASCAN1" />
</bean>
在wildfly中添加了数据源
请大家帮忙,如何解决这个问题?
谢谢