Reputation: 2473
Here is my server.xml, I am getting javax.naming.NameNotFoundException: Name UserDatabase is not bound in this Context. If I remove the Realm then I getjavax.naming.NameNotFoundException:datsource not found in this context. What wrong here ?
<?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 I have added below lines
<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>
Upvotes: 0
Views: 243
Reputation: 11835
Here is what works for me:
name = "jdbc/myDatabase"
in Tomcat's <Resource>
and
java:/comp/env/jdbc/myDatabase
in Spring's JndiObjectFactoryBean.jndiName
.
Upvotes: 1