How can I prevent Tomcat6 from pre-loading JDBC Dr

2019-09-09 10:31发布

问题:

I have a number of JDBC Driver jar files in my webapp's WEB-INF/lib - e.g. oracle and SQL-Server. In Tomcat7, if the webapp only uses oracle, the SQL-Server driver doesn't get registered, but in Tomcat6 it does (I can see this from my contextDestroyed() in a ServletContextListener, which de-registers Drivers loaded by this classloader).

Is Tomcat6 somehow pre-loading classes from jars in WEB-INF/lib? If so, can this be disabled?

(I know these jars would be better in the shared lib, but this is another issue...)

回答1:

Never ever put drivers in the webapp class path. Put it always into the server's classpath.

Declare a DataSource then in your context.xml and then free the resources with this.



标签: java tomcat jdbc