带事宜得spring配置文件
带事务得spring配置文件
<?xml version="1.0" encoding="UTF-8" ?> - <!-- <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" --> - <!-- " http://www.springframework.org/dtd/spring-beans.dtd"> --> - <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"> - <!-- <bean id="sessionFactory" --> - <!-- class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> --> - <!-- <property name="configLocation"> --> - <!-- <value>classpath:hibernate.cfg.xml</value> --> - <!-- </property> --> - <!-- </bean> --> - <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="com.microsoft.jdbc.sqlserver.SQLServerDriver" /> <property name="url" value="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=epet;SelectMethod=cursor" /> <property name="username" value="sa" /> <property name="password" value="pwd" /> </bean> - <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> - <property name="dataSource"> <ref local="dataSource" /> </property> - <property name="mappingResources"> - <list> <value>com/aptech/jb/epet/entity/PetInfo.hbm.xml</value> <value>com/aptech/jb/epet/entity/PetDiary.hbm.xml</value> </list> </property> - <property name="hibernateProperties"> - <props> <prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop> <prop key="hibernate.show_sql">true</prop> </props> </property> </bean> - <bean id="myHibTxManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> - <tx:advice id="txAdvice" transaction-manager="myHibTxManager"> - <tx:attributes> - <!-- 对get/load/search开头的方法要求只读事务 --> <tx:method name="get*" propagation="SUPPORTS" read-only="true" /> <tx:method name="load*" propagation="SUPPORTS" read-only="true" /> <tx:method name="search*" propagation="SUPPORTS" read-only="true" /> <tx:method name="find*" propagation="SUPPORTS" read-only="true" /> - <!-- 对其它方法要求事务 --> <tx:method name="*" propagation="REQUIRED" /> </tx:attributes> </tx:advice> - <aop:config> - <!-- 只对GoodsBiz添加事务支持,因为前面配置的transactionManager 是专对Hibernate的事务管理器 。 --> <aop:pointcut id="bizMethods" expression="execution(* com.aptech.jb.epet.biz.*.*(..))" /> - <!-- 织入 --> <aop:advisor advice-ref="txAdvice" pointcut-ref="bizMethods" /> </aop:config> - <!-- DAO --> - <bean id="petInfoDAO" class="com.aptech.jb.epet.dao.hibimpl.PetInfoDAOHibImpl"> <property name="sessionFactory" ref="sessionFactory" /> </bean> - <bean id="petDiaryDAO" class="com.aptech.jb.epet.dao.hibimpl.PetDiaryDAOHibImpl"> <property name="sessionFactory" ref="sessionFactory" /> </bean> - <!-- BIZ --> - <bean id="petInfoBiz" class="com.aptech.jb.epet.biz.impl.PetInfoBizImpl"> <property name="petInfoDAO" ref="petInfoDAO" /> </bean> - <bean id="petDiaryBiz" class="com.aptech.jb.epet.biz.impl.PetDiaryBizImpl"> <property name="petDiaryDAO" ref="petDiaryDAO" /> </bean> - <!-- ACTION --> - <bean name="/pet" class="com.aptech.jb.epet.web.action.PetAction"> <property name="petInfoBiz" ref="petInfoBiz" /> </bean> - <bean name="/login" class="com.aptech.jb.epet.web.action.PetAction"> <property name="petInfoBiz" ref="petInfoBiz" /> </bean> - <bean name="/diary" class="com.aptech.jb.epet.web.action.DiaryAction"> <property name="petDiaryBiz" ref="petDiaryBiz" /> </bean> </beans>