<?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:p="http://www.springframework.org/schema/p" 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 "> <!-- DAO Instance -- <bean id="Deptdao" class="Cn.itcast.dao.DeptDao"> <property name="sessionfactory" ref="Sessionfactory"></property> </bean> <!--service instance -- <bean id="Deptservice" class="Cn.itcast.service.DeptService"> <property name="Deptdao" ref="Deptdao"></property> </bean> <!-- Data source configuration -- <bean id="DataSource" class="Com.mchange.v2.c3p0.ComboPooledDataSource"> <property name="Driverclass" value="Com.mysql.jdbc.Driver"></property> <property name="Jdbcurl" value="Jdbc:mysql:///hib_demo"></property> <property name="user" value="root"></property> <property name="Password " value="root"></property> <property name= "initialpoolsize " value="3"></property> <property name="maxpoolsize " value="ten"></property> <property name="maxstatements " value="></property>" <property name= "acquireincrement " value="2"></property> </bean> <!--########## #Spring and Hibernate integration start########### -- <!-- Way (1) Direct loading of hibernate.cfg.xml files in a way that integrates <bean id= "Sessionfactory" class= "Org.springframework.orm.hibernate3.LocalSessionFactoryBean" > <property name= "configlocation" value= "Classpath:hibernate.cfg.xml" ></property> </bean> <!-- Way (2) connect pool to Spring Management "Part of the configuration is written to hibernate , one in In spring , complete the <bean id= "Sessionfactory" class= "Org.springframework.orm.hibernate3.LocalSessionFactoryBean" > <property name= "configlocation" value= "Classpath:hibernate.cfg.xml" ></property> <property name= "DataSource" ref= "DataSource" ></property> </bean> <!-- "recommended" Way (3) All configurations are done in the Spring configuration file - <bean id="sessionfactory" class="Org.springframework.orm.hibernate3.LocalSessionFactoryBean" > <!-- inject connection pool objects -- <property name="DataSource" ref="DataSource"></property> <!-- hibernate Common configuration - <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> </props> </property> <!-- Hibernate Mapping configuration <property name= "Mappinglocations" > <list> <value>classpath:cn/itcast/entity/*.hbm.xml</value> </list> </property> - <property name="Mappingdirectorylocations"> <list> <value>classpath:cn/itcast/entity/</value> </list> </property> </bean> <!--########## #Spring and Hibernate integration end########### -- <!-- transaction configuration -- <!--A. Configure the transaction manager class -- <bean id="Txmanager" class="Org.springframework.orm.hibernate3.HibernateTransactionManager " > <property name="sessionfactory" ref="Sessionfactory"></property> </bean> <!--b. configuring transaction Enhancement ( after blocking to a method if management transaction ?) -- <tx:advice id="Txadvice" transaction-manager="Txmanager"> <tx:attributes> <tx:method name="*" read-only="false"/> </tx:attributes> </tx:advice> <!--c. Aop Configuration -- <aop:config> <aop:pointcut expression="Execution (* cn.itcast.service.*.* (..))" id="pt"/> <aop:advisor advice-ref="Txadvice" pointcut-ref="pt"/> </aop:config> </beans> |