问题
I am using apache-tomcat-6.0.37, spring 2.5.6 and tomcat-jdbc-7.0.19.When configuring org.apache.tomcat.jdbc.pool.DataSource in xml file, I am getting this error:
org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.apache.tomcat.jdbc.pool.DataSource].
Does spring 2.5.6 does not support tomcat-jdbc-7.0.19? Do it need higher version of spring? At this current moment I can not shift to higher version. Do I need to get conform?
回答1:
Your JARs are outdated first of all.
- Update to the most recent Tomcat JDBC Pool
- Put that JAR and your driver into
$CATALINA_*/liband nowhere else (*==HOMEorBASE) - Declare your
DataSourcein yourcontext.xml - Retrieve that
DataSourcefrom yourbeans.xmlwith a JNDI lookup
Tomcat JDBC Pool works flawlessly with Tomcat 6 as long as your run Java 6.
Here is a very similar question.
回答2:
Right now the error you are getting is Cannot find class, this means that the following class is not in the classpath. You should check if jar is present in classpath or not.
Probable location (Since it doesn't get shipped with tomcat-6.x):
- WEB-INF/lib directory of war file.
By reading from the documentation, I guess tomcat-jdbc is something introduced in tomcat-7.x not in tomcat-6.x so I doubt if it will work as expected.
Link of interest: http://people.apache.org/~fhanik/jdbc-pool/jdbc-pool.html
回答3:
These two stack overflow links will solve your problems.
org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class
Spring Web App - CannotLoadBeanClassException caused by Java.lang.ClassNotFoundException
回答4:
The problem is solved .Though the class path of jar was present in .class file generated by ecclipse .I have forgotten to include in build.xml.So the jar was missing in lib of tomcat.
来源:https://stackoverflow.com/questions/17037509/tomcat-jdbc-and-spring-version-compatability