java - Spring MVC project cannot use Hibernate -
i want build spring mvc project hibernate.
the ide used eclipse 4.4.2(luna) , installed plugin spring tool suite (sts) eclipse luna (4.4).
the project create spring project > spring mvc project.
here external jars add :
- antlr-2.7.7.jar
- dom4j-1.6.1.jar
- hibernate-commons-annotations-4.0.5.final.jar
- hibernate-core-4.3.9.final.jar
- hibernate-jpa-2.1-api-1.0.0.final.jar
- jandex-1.1.0.final.jar
- javassist-3.18.1-ga.jar
- jboss-logging-3.1.3.ga.jar
- jboss-logging-annotations-1.2.0.beta1.jar
- jboss-transaction-api_1.2_spec-1.0.0.final.jar
- mysql-connector-java-5.0.8-bin.jar
then, add detail of database /src/main/webapp/web-inf/spring/appservlet/servlet-context.xml :
<beans:bean id="datasource" class="org.springframework.jdbc.datasource.drivermanagerdatasource"> <beans:property name="driverclassname" value="com.mysql.jdbc.driver" /> <beans:property name="url" value="jdbc:mysql://192.168.1.43/mydatabase" /> <beans:property name="username" value="testuser" /> <beans:property name="password" value="thepassoftheuser" /> </beans:bean>
however, shows error message :
org.springframework.beans.factory.beancreationexception: error creating bean name 'datasource' defined in servletcontext resource [/web-inf/spring/appservlet/servlet-context.xml]: instantiation of bean failed; nested exception org.springframework.beans.beaninstantiationexception: not instantiate bean class [org.springframework.jdbc.datasource.drivermanagerdatasource]: constructor threw exception; nested exception java.lang.noclassdeffounderror: org/apache/commons/logging/logfactory java.lang.noclassdeffounderror: org/apache/commons/logging/logfactory org.springframework.jdbc.datasource.abstractdatasource.<init>(abstractdatasource.java:37) org.springframework.jdbc.datasource.drivermanagerdatasource.<init>(drivermanagerdatasource.java:87)
since cannot fix it, tried write hibernate.cfg.xml, have no idea file should put.
i want know how set bean let project can use hibernate , how use transitional way of hibernate (hibernate.cfg.xml) in mvc project.
may 19th added
i found solution.
it because maven didn't load hibernate. therefore after adding following code pom.xml can work:
<dependency> <groupid>org.hibernate</groupid> <artifactid>hibernate-entitymanager</artifactid> <version>3.6.0.final</version> </dependency> <dependency> <groupid>org.hibernate</groupid> <artifactid>hibernate-core</artifactid> <version>3.6.0.final</version> </dependency> <dependency> <groupid>com.h2database</groupid> <artifactid>h2</artifactid> <version>1.3.156</version> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-jdbc</artifactid> <version>4.0.6.release</version> </dependency>
your error related missing library in classpath. is:
org.apache.commons.logging
try fix first tell if problem still occurs.
Comments
Post a Comment