Tomcat 8.5 无法找到 [jdbc]
Tomcat 8.5 Unable to find [jdbc]
我正在尝试将应用程序从 WebLogic 迁移到 Tomcat,但在启动 tomcat 时遇到异常。
Caused by: javax.naming.NameNotFoundException: Name [jdbc/datasource] is not bound in this Context. Unable to find [jdbc].
at org.apache.naming.NamingContext.lookup(NamingContext.java:816)
at org.apache.naming.NamingContext.lookup(NamingContext.java:173)
at org.apache.naming.SelectorContext.lookup(SelectorContext.java:163)
at javax.naming.InitialContext.lookup(InitialContext.java:417)
at org.springframework.jndi.JndiTemplate.doInContext(JndiTemplate.java:155)
at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:87)
at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:152)
at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:179)
at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:95)
at org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.java:106)
at org.springframework.jndi.JndiObjectFactoryBean.lookupWithFallback(JndiObjectFactoryBean.java:231)
at org.springframework.jndi.JndiObjectFactoryBean.afterPropertiesSet(JndiObjectFactoryBean.java:217)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
... 60 more
我在server.xml中的数据源定义如下;
<GlobalNamingResources>
<Resource name="jdbc/datasource" auth="Container" type="javax.sql.DataSource"
username="username" password="password"
driverClassName="oracle.jdbc.OracleDriver"
url="jdbc:oracle:thin:blablabla" />
</GlobalNamingResources>
同样在context.xml如下;
<ResourceLink name="jdbc/datasource"
global="jdbc/datasource"
type="javax.sql.DataSource"/>
我该如何解决这个问题?
我找到了解决方案。属性文件中有一个数据源定义,我删除了它,在该应用程序在 tomcat context.xml 中找到 jdbc 定义后,成功启动。
在我的例子中:我不得不把它放在 webapp/META-INF/context.xml
下。这与常规 META-INF/
.
不同
我正在尝试将应用程序从 WebLogic 迁移到 Tomcat,但在启动 tomcat 时遇到异常。
Caused by: javax.naming.NameNotFoundException: Name [jdbc/datasource] is not bound in this Context. Unable to find [jdbc].
at org.apache.naming.NamingContext.lookup(NamingContext.java:816)
at org.apache.naming.NamingContext.lookup(NamingContext.java:173)
at org.apache.naming.SelectorContext.lookup(SelectorContext.java:163)
at javax.naming.InitialContext.lookup(InitialContext.java:417)
at org.springframework.jndi.JndiTemplate.doInContext(JndiTemplate.java:155)
at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:87)
at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:152)
at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:179)
at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:95)
at org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.java:106)
at org.springframework.jndi.JndiObjectFactoryBean.lookupWithFallback(JndiObjectFactoryBean.java:231)
at org.springframework.jndi.JndiObjectFactoryBean.afterPropertiesSet(JndiObjectFactoryBean.java:217)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
... 60 more
我在server.xml中的数据源定义如下;
<GlobalNamingResources>
<Resource name="jdbc/datasource" auth="Container" type="javax.sql.DataSource"
username="username" password="password"
driverClassName="oracle.jdbc.OracleDriver"
url="jdbc:oracle:thin:blablabla" />
</GlobalNamingResources>
同样在context.xml如下;
<ResourceLink name="jdbc/datasource"
global="jdbc/datasource"
type="javax.sql.DataSource"/>
我该如何解决这个问题?
我找到了解决方案。属性文件中有一个数据源定义,我删除了它,在该应用程序在 tomcat context.xml 中找到 jdbc 定义后,成功启动。
在我的例子中:我不得不把它放在 webapp/META-INF/context.xml
下。这与常规 META-INF/
.