Hello everybody,
I'm trying to move a global jdbc resource out of server.xml so it is
application specific. Following is the server.xml (which works fine)
<?xml version="1.0" encoding="UTF-8"?>
<Server port="8005" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.core.AprLifecycleListener"/>
<Listener className="org.apache.catalina.mbeans.ServerLifecycleListener
"/>
<Listener className="
org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
<Listener className="
org.apache.catalina.storeconfig.StoreConfigLifecycleListener"/>
<GlobalNamingResources>
<Resource auth="Container" driverClassName="com.mysql.jdbc.Driver"
maxActive="10" maxIdle="1" maxWait="10000" name="jdbc/sandwiches"
password="tomcat" type="javax.sql.DataSource"
url="jdbc:mysql://192.168.16.39:3306/sandwiches?autoReconnect=true"
username="tomcat"/>
</GlobalNamingResources>
<Service name="Catalina">
<Connector acceptCount="100" connectionTimeout="20000"
disableUploadTimeout="true" enableLookups="false" maxHttpHeaderSize="8192"
maxSpareThreads="75" maxThreads="150" minSpareThreads="25" port="8080"
redirectPort="8443"/>
<Connector enableLookups="false" port="8009" protocol="AJP/1.3"
redirectPort="8443"/>
<Engine defaultHost="laocalhost" name="Catalina">
<Realm className="org.apache.catalina.realm.DataSourceRealm"
dataSourceName="jdbc/sandwiches" debug="99" roleNameCol="role"
userCredCol="password" userNameCol="user" userRoleTable="userroles"
userTable="users"/>
<Host appBase="webapps" autoDeploy="true" name="localhost"
unpackWARs="true" xmlNamespaceAware="false" xmlValidation="false">
</Host>
</Engine>
</Service>
</Server>
What I did was remove the the <GlobalNamingResources> and <Realm > elements
from server.xml and put them inside
$CATALINA_HOME/conf/Catalina/localhost/esandwich.xml (don't mind the weird
name :) ), but I keep getting the error
"javax.naming.NameNotFoundException: Name jdbc is not bound in this Context"
esandwich.xml:
<Context docBase="c:/workspace/esandwich/WebContent/" reloadable="true"
crosscontext="true">
<Resource name="jdbc/sandwiches" auth="Container" driverClassName="
com.mysql.jdbc.Driver"
password="tomcat" type="javax.sql.DataSource"
url="jdbc:mysql://192.168.16.39:3306/sandwiches?autoReconnect=true"
username="tomcat" />
<Realm className="org.apache.catalina.realm.DataSourceRealm"
dataSourceName="jdbc/sandwiches" debug="99" roleNameCol="role"
userCredCol="password" userNameCol="user" userRoleTable="userroles"
userTable="users" />
</Context>
I believe the problem lies witht he <Resource> element because if only move
the <realm> element to the esandwich.xml and leave the
<GlobalNamingResources><Resource.....></...> in server.xml everything still
works. We've been searching for a few hours now and can't find the solution.
Any help would be highly appreciated.
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>esandwich</display-name>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/app/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<login-config>
<auth-method>FORM</auth-method>
<form-login-config>
<form-login-page>/login.html</form-login-page>
<form-error-page>/loginError.html</form-error-page>
</form-login-config>
</login-config>
<security-constraint>
<web-resource-collection>
<web-resource-name>default</web-resource-name>
<url-pattern>/app/*</url-pattern>
<http-method>POST</http-method>
<http-method>GET</http-method>
</web-resource-collection>
<auth-constraint>
<description>everyone can log in</description>
<role-name>*</role-name>
</auth-constraint>
</security-constraint>
<security-role>
<description>The Only Secure Role</description>
<role-name>admin</role-name>
</security-role>
</web-app>
Many thanks in advance,
Glen.