Recently consolidated SPRING4 and Hibernate4,beans.xml are as follows
<?xml version= "1.0" encoding= "UTF-8"? ><beans xmlns= "http://www.springframework.org/ Schema/beans " xmlns:xsi=" Http://www.w3.org/2001/XMLSchema-instance " xmlns:context= "Http://www.springframework.org/schema/context" xmlns:aop= "http// Www.springframework.org/schema/aop " xmlns:tx=" http://www.springframework.org/ Schema/tx " xsi:schemalocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd "> <context:annotation-config></context: Annotation-config> <tx:annotation-driven transaction-manager= " TransactionManager "/> <bean id=" Userdao " class=" Dao.impl.UserDaoImpl " ></bean><bean id= "UserService" class= "service. UserService "></bean><bean id=" DataSource " class=" Org.apache.commons.dbcp.BasicDataSource "> <property name=" Driverclassname " value=" Com.mysql.jdbc.Driver "/> <property name=" url " value=" JDBC: Mysql://localhost:3306/spring "/> <property name=" username "&Nbsp;value= "root"/> <property name= "password" value= " 19870509 "/> </bean> <bean id=" TransactionManager " class= "Org.springframework.orm.hibernate3.HibernateTransactionManager" > <property name= "Sessionfactory" ref= "SessionFactory" />< /bean> <bean id= "Sessionfactory" class= " Org.springframework.orm.hibernate4.LocalSessionFactoryBean "> <property name= "DataSource" ref= "DataSource" /> <property name= "Hibernateproperties" > <props> <prop key= "Hibernate.dialect" >org.hibernate.dialect.MySQLDialect</prop> <prop key= " Hibernate.show_sql ">true</prop> <prop key= "Hibernate.hbm2ddl.auto" >update</prop> <prop key= "Hibernate.format_sql" >true</prop> </props> </ Property> <property name= "AnnotatedClasses" > <list> &nBsp; <value>model. user</value> </ list> </property> </bean> </beans>
Spring and Hibernate versions are all 4, but the test is reported java.lang.NoSuchMethodError:org.hibernate.Session.openSession () abnormal, and later looked for a long time, It is said that the Hibernate4 version needs Spring4 to support, but mine is 4. Then I began to look at my beans.xml and found that it was wrong here:
<bean id= "TransactionManager" class= "Org.springframework.orm.hibernate3.HibernateTransactionManager" >
Change into
<bean id= "TransactionManager" class= "Org.springframework.orm.hibernate4.HibernateTransactionManager" >
Can.
Java.lang.NoSuchMethodError:org.hibernate.Session