Spring configuration file
<?XML version= "1.0" encoding= "UTF-8"?><Beansxmlns= "Http://www.springframework.org/schema/beans"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"XMLNS:AOP= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP"Xmlns:context= "Http://www.springframework.org/schema/context"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/AOP http://www.springframework.org/schema/aop/spring-aop-4.0.xsd/HTTP Www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd http ://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd "> <!--Import Resource File - <Context:property-placeholder Location= "Classpath:db.properties" /> <!--configuring C3P0 Data Sources - <BeanID= "DataSource"class= "Com.mchange.v2.c3p0.ComboPooledDataSource"> < Propertyname= "User"value= "${user}"></ Property> < Propertyname= "Password"value= "${password}"></ Property> < Propertyname= "Jdbcurl"value= "${jdbcurl}"></ Property> < Propertyname= "Driverclass"value= "${driverclass}"></ Property> < Propertyname= "Initialpoolsize"value= "${initpoolsize}"></ Property> < Propertyname= "Maxpoolsize"value= "${maxpoolsize}"></ Property> </Bean> <!--Configure Sessionfactory - <BeanID= "Sessionfactory"class= "Org.springframework.orm.hibernate4.LocalSessionFactoryBean"> < Propertyname= "DataSource"ref= "DataSource"></ Property> < Propertyname= "Configlocation"value= "Classpath:hibernate.cfg.xml"></ Property> < Propertyname= "Mappinglocations"value= "Classpath:com/entities/*.hbm.xml"></ Property> </Bean> <!--configuring Spring's declarative Transactions - <!--1. Configure Hibernate's transaction manager - <BeanID= "TransactionManager"class= "Org.springframework.orm.hibernate4.HibernateTransactionManager"> < Propertyname= "Sessionfactory"ref= "Sessionfactory"></ Property> </Bean> <!--2. Configure transaction Properties - <Tx:adviceID= "Txadvice"Transaction-manager= "TransactionManager"> <tx:attributes> <Tx:methodname= "*get*"read-only= "true"/> <Tx:methodname="*"/> </tx:attributes> </Tx:advice> <!--3. Configure the transaction pointcut, and then associate the transaction properties with the transaction pointcut - <Aop:config> <Aop:pointcutexpression= "Execution (* com.service.*.* (..))"ID= "Txpointcut"/> <Aop:advisorAdvice-ref= "Txadvice"Pointcut-ref= "Txpointcut"/> </Aop:config> </Beans>
Hibernate configuration file
<?XML version= "1.0" encoding= "UTF-8"?><!DOCTYPE hibernate-configuration Public "-//hibernate/hibernate configuration DTD 3.0//en" "Http://hibern Ate.sourceforge.net/hibernate-configuration-3.0.dtd "><hibernate-configuration> <session-factory> <!--Configure basic properties for Hibernate - <!--dialect - < Propertyname= "Hibernate.dialect">Org.hibernate.dialect.MySQL5InnoDBDialect</ Property> <!--whether to display and format SQL - < Propertyname= "Hibernate.show_sql">True</ Property> < Propertyname= "Hibernate.format_sql">True</ Property> <!--policies for generating data tables - < Propertyname= "Hibernate.hbm2ddl.auto">Update</ Property> <!--level Two cache correlation - </session-factory></hibernate-configuration>
Xml
<Context-param> <Param-name>Contextconfiglocation</Param-name> <Param-value>Classpath:applicationContext.xml</Param-value> </Context-param> <Listener> <Listener-class>Org.springframework.web.context.ContextLoaderListener</Listener-class> </Listener>
Directory structure
Jar Package
Spring Integration Hibernate