It's been a long time since I used the spring framework, and it's been struts2+hibernate4 to build Web projects, and lately, to learn something about spring, spring is the most widely used framework now, and will work in this industry, so it's necessary to learn.
The spring framework is added first and can be run correctly;
The hibernate framework is then added in a separate generation of hibernate.cfg.xml, using the default DAO file rather than the DAO file style under the spring framework;
After the frame is added, the hibernate frame can be used alone when the spring frame is used alone, but there is a problem when running the Web project, and the console response is a datasource problem, searching the internet for a bit, When you add code to Spring-mvc.xml, the Web project runs. Reference Link: http://blog.csdn.net/zxygww/article/details/45914193
Add code:
<!--handling DataSource errors --
<bean id= "sessionfactory" class= "Org.springframework.orm.hibernate4.LocalSessionFactoryBean" >
<property name= "Configlocation" >
<value>classpath:hibernate.cfg.xml</value>
</property>
</bean>
<bean id= "datasource" class= "Org.springframework.jdbc.datasource.DriverManagerDataSource"/>
<bean id= "TransactionManager" class= "Org.springframework.orm.hibernate4.HibernateTransactionManager" >
<property name= "sessionfactory" ref= "Sessionfactory" ></property>
<property name= "DataSource" ref= "DataSource" ></property>
</bean>
Wherein,classpath:hibernate.cfg.xml refers to: Hibernate.cfg.xml file in src root directory
It seems that the convergence of the spring framework and the Hibernate framework still needs to be improved.
Spring + Hibernate Framework