Applicationcontext-dao.xml
<?XML version= "1.0" encoding= "UTF-8"?><Beansxmlns= "Http://www.springframework.org/schema/beans"Xmlns:context= "Http://www.springframework.org/schema/context"XMLNS:AOP= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP"Xmlns:tx= "Http://www.springframework.org/schema/tx"xmlns:p= "http://www.springframework.org/schema/p"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xsi:schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/ Spring-beans-4.2.xsd Http://www.springframework.org/schema/context Http://www.springframework.org/schema/context /spring-context-4.2.xsd HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP http://www.springframework.org/schema/aop/ Spring-aop-4.2.xsd Http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/ Spring-tx-4.2.xsd "> <!--To open a scan annotation bean - <Context:component-scanBase-package= "Com.hao" /> <Context:property-placeholder Location= "Classpath:db.properties" /> <BeanID= "DataSource"class= "Com.mchange.v2.c3p0.ComboPooledDataSource"> < Propertyname= "Driverclass"value= "${jdbc.driverclass}" /> < Propertyname= "Jdbcurl"value= "${jdbc.jdbcurl}" /> < Propertyname= "User"value= "${jdbc.user}" /> < Propertyname= "Password"value= "${jdbc.password}" /> </Bean> <!--Load Configuration Scenario 2: Place hibernate configuration information in the spring configuration - <Beanname= "Sessionfactory"class= "Org.springframework.orm.hibernate5.LocalSessionFactoryBean"> <!--inject the connection pool into the sessionfactory, hibernate will get the connection through the connection pool - < Propertyname= "DataSource"ref= "DataSource"></ Property> <!--Configure Hibernate basic information - < Propertyname= "Hibernateproperties"> <Props> <propKey= "Hibernate.dialect">Org.hibernate.dialect.MySQLDialect</prop> <propKey= "Hibernate.show_sql">True</prop> <propKey= "Hibernate.format_sql">True</prop> <propKey= "Hibernate.hbm2ddl.auto">Update</prop> </Props> </ Property> <!--introduces ORM metadata, specifying the package path where ORM metadata resides, and spring automatically reads all the configurations in the package - < Propertyname= "Packagestoscan"value= "Com.hao.entity"></ Property> </Bean></Beans>
Applicationcontext-service.xml
<?XML version= "1.0" encoding= "UTF-8"?><Beansxmlns= "Http://www.springframework.org/schema/beans"Xmlns:context= "Http://www.springframework.org/schema/context"XMLNS:AOP= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP"Xmlns:tx= "Http://www.springframework.org/schema/tx"xmlns:p= "http://www.springframework.org/schema/p"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xsi:schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/ Spring-beans-4.2.xsd Http://www.springframework.org/schema/context Http://www.springframework.org/schema/context /spring-context-4.2.xsd HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP http://www.springframework.org/schema/aop/ Spring-aop-4.2.xsd Http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/ Spring-tx-4.2.xsd "> <Beanname= "TransactionManager"class= "Org.springframework.orm.hibernate5.HibernateTransactionManager"> < Propertyname= "Sessionfactory"ref= "Sessionfactory" /> </Bean> <Tx:annotation-drivenTransaction-manager= "TransactionManager" /></Beans>
Applicationcontext-*.xml