When I run the following code on one machine I get tomcat implementation of org.apache.tomcat.dbcp.dbcp.BasicDataSource
and when I run it on another machine I get apache commons implementations of org.apache.commons.dbcp.BasicDataSource
(which obviously results in ClassCastException
). Just wondering why no change in code and context.xml
would result in returning two different implementations of DataSource?
Context context = (Context) initialContext.开发者_开发知识库lookup("java:/comp/env");
return (DataSource) context.lookup("jdbc/dbName");
I suppose you are not including DBCP inside your war. So it's using whatever DataSource is configured in Tomcat. You're probably using two different versions of Tomcat, or at least they have been configured differently; one must have commons-dbcp.jar and the other one has tomcat-dbcp.jar.
精彩评论