2017-04-25 54 views
0

这里是我的server.xml中,我得到 javax.naming.NameNotFoundException:名称UserDatabase没有在这方面的约束。如果我删除域然后我getjavax.naming.NameNotFoundException:在这方面没有发现datsource。这里有什么不对?无法配置JNDI DATABSE在春季和Tomcat

<?xml version="1.0" encoding="UTF-8"?> 
<Server port="8005" shutdown="SHUTDOWN"> 
<Listener SSLEngine="on" 
    className="org.apache.catalina.core.AprLifecycleListener" /> 
<Listener className="org.apache.catalina.core.JasperListener" /> 
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" /> 
<Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" /> 
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" /> 
<GlobalNamingResources> 
    <Resource auth="Container" description="Pas testing UCP Pool in Tomcat" 
     driverClassName="oracle.jdbc.OracleDriver" maxIdle="10" maxWait="-1" 
     name="myDatabase" password="abc123" pathname="conf/context.xml" 
     readOnly="true" type="javax.sql.DataSource" 
     url="myurl" user="admin" 
     vreadOnly="true" xActive="20" /> 
</GlobalNamingResources> 
<Service name="Catalina"> 
    <Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" 
     redirectPort="8443" /> 
    <!-- Define an AJP 1.3 Connector on port 8009 --> 
    <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /> 

    <Engine defaultHost="localhost" name="Catalina"> 
     <Realm className="org.apache.catalina.realm.UserDatabaseRealm" 
      resourceName="UserDatabase" /> 

     <Host appBase="webapps" autoDeploy="true" name="localhost" 
      unpackWARs="true" xmlNamespaceAware="false" xmlValidation="false"> 
     </Host> 
    </Engine> 
</Service> 
</Server> 

的context.xml

<?xml version="1.0" encoding="UTF-8"?> 
<Context> 
<!-- Default set of monitored resources --> 
<ResourceLink auth="Container" global="myDatabase" 
    name="myDatabase" type="javax.sql.DataSource" /> 
<WatchedResource>WEB-INF/web.xml</WatchedResource> 

</Context> 

的Spring bean XML

<beans xmlns="http://www.springframework.org/schema/beans" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:aop="http://www.springframework.org/schema/aop" 
xmlns:tx="http://www.springframework.org/schema/tx" 
xsi:schemaLocation=" 
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd 
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd 
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"> 
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean"> 
     <property name="jndiName" value="myDatabase"/> 
</bean> 

web.xml中我已经加入以下行

<resource-ref> 
    <description>DB Connection</description> 
    <res-ref-name>CitilinxJdbcDatasource</res-ref-name> 
    <res-type>javax.sql.DataSource</res-type> 
    <res-auth>Container</res-auth> 
</resource-ref> 
+0

错误详细信息:org.springframework.beans.factory.BeanCreationException:在类路径资源[spring/ibatis-context.xml]中定义的名为'dataSource'的bean创建时出错:init方法的调用失败;嵌套异常是javax.naming.NameNotFoundException:名称myDatabase没有在此上下文中绑定 –

+1

适用于我的是:在Tomcat的''和'java:/ comp/env/jdbc/myDatabase'中的'name =“jdbc/myDatabase”在Spring的'JndiObjectFactoryBean.jndiName' –

+0

这对我来说工作.. :)。谢谢 –

回答

1

这里对我来说是什么工作:

name = "jdbc/myDatabase" 

Tomcat的<Resource>

java:/comp/env/jdbc/myDatabase 

在Spring的JndiObjectFactoryBean.jndiName