The Tomcat documentation lists several different places that you can
define a Context element. I don't want to define it in my app's web.xml
Neither should you. Web.xml has its own purpose defined by the servlet spec.
My web app is in a war called mytest.war, which I deployed to
$CATALINA_HOME/webapps. My web.xml has the following elements:
You'll have to add a resource-ref block to this. See the tomcat JDBC
howto docs for details. Otherwise it looks good.
<Context path="/mytest" docBase="mytest"
debug="5" reloadable="true" crossContext="true">
Drop the path and docBase attributes. They are at best duplicate of
information tomcat can glean from other sources. You can also put this
in a file named context.xml in the META-INF directory of your war file.
<Resource name="jdbc/mytest" auth="Container"
type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="javauser" password="javadude"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/mytest?autoReconnect=true"/>
Drop autoReconnect=true and replace it with a new attribute
validationQuery="select 1" on the Resource element. It'll handle stale
connections much better.
--David
Michael Burbidge wrote:
I'm trying to define a JNDI resource for a datasource. The Tomcat
documentation lists several different places that you can define a
Context element. I don't want to define it in my app's web.xml and I
don't want to modify tomcat config files. I want to define a companion
file for my app, but I'm having a hard time understanding the
documentation. It says the following, is one place you can define a
Context element:
in individual files (with a ".xml" extension) in the
$CATALINA_HOME/conf/[enginename]/[hostname]/ directory. The name of
the file (less the .xml) extension will be used as the context path.
Multi-level context paths may be defined using #, e.g.context#path.xml.
My web app is in a war called mytest.war, which I deployed to
$CATALINA_HOME/webapps. My web.xml has the following elements:
<servlet>
<servlet-name>mytest</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mytest</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
I placed a file named mytest.xml in
$CATALINA_HOME/conf/Catalina/localhost/mytest.xml. mytest.xml contains
the following:
<Context path="/mytest" docBase="mytest"
debug="5" reloadable="true" crossContext="true">
<Resource name="jdbc/mytest" auth="Container"
type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="javauser" password="javadude"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/mytest?autoReconnect=true"/>
</Context>
My Context defined this way is not loaded. I've checked using the
Tomcat Manager and there is no JNDI resource loaded. What am I doing
wrong?
Thanks,
Michael-
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]