java spring 事务配置: <?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:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd "> <!-- beans --> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="configLocation" value="classpath:hibernate.cfg.xml"> </property> </bean> <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate"> <property name="sessionFactory"> <ref bean="sessionFactory"/> </property> </bean> <bean id="candidateManager" class="DM2.service.CandidateManager"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <bean id="resumeTemplateManager" class="DM2.service.ResumeTemplateManager"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <bean id="customFElayoutManager" class="DM2.service.CustomFrontendlayoutpageManager"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <bean id="jobDetailsManager" class="DM2.service.JobDetailsManager"> <property name="sessionFactory"> <ref bean="sessionFactory"/> </property> </bean> <!-- <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"><property name="sessionFactory" ref="sessionFactory" /></bean> <bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor"> <property name="transactionManager" ref="transactionManager" /> <property name="transactionAttributes"> <props> <prop key="query*">PROPAGATION_REQUIRED,readOnly</prop> <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop> <prop key="find*">PROPAGATION_REQUIRED,readOnly</prop> <prop key="view*">PROPAGATION_REQUIRED,readOnly</prop> <prop key="merge*">PROPAGATION_REQUIRED,readOnly</prop> <prop key="update*">PROPAGATION_REQUIRED</prop> <prop key="insert*"> PROPAGATION_REQUIRED,-GenericException </prop> </props> </property> </bean> --> <!-- 配置事务管理器--> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory"> <ref bean="sessionFactory" /> </property> </bean> <!--配置事务的传播特性 --> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="add*" propagation="REQUIRED" /> <tx:method name="delete*" propagation="REQUIRED" /> <tx:method name="modify*" propagation="REQUIRED" /> <tx:method name="update*" propagation="REQUIRED" /> <tx:method name="*" read-only="true" /> </tx:attributes> </tx:advice> <!--那些类的哪些方法参与事务 --> <aop:config proxy-target-class="true"> <aop:pointcut id="allManagerMethod" expression="execution(* DM2.service.*.*(..))" /> <aop:advisor pointcut-ref="allManagerMethod" advice-ref="txAdvice" /> </aop:config> <!--scan page--> <context:component-scan base-package="DM2.web" /> <bean name="openSessionInViewInterceptor" class="org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor"> <property name="sessionFactory"><ref bean="sessionFactory"/></property> </bean> <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" > <property name="interceptors"> <list> <ref bean="openSessionInViewInterceptor"/> </list> </property> </bean> <!-- 启动Spring MVC的注解功能,完成请求和注解POJO的映射 --> <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" /> <!-- urls --> <!-- <bean name="/TestTagToXslt.html" class="DM2.web.TestTagToXsltController"></bean> <bean name="/TestResumeFormXml.html" class="DM2.web.TestResumeFormXmlController"/>--> <bean name="/TestNH.html" class="DM2.web.TestNHController"/> <!-- <bean name="/TestResumeFormV2.html" class="DM2.web.TestResumeFormV2Controller"> <property name="candidateManager"> <ref bean="candidateManager"/> </property> <property name="resumeTemplateManager"> <ref bean="resumeTemplateManager"/> </property> </bean>--> <bean name="/hello_world.html" class="DM2.web.HelloWorldController"/> <!-- bean name="/TestResumeForm.html" class="DM2.web.TestResumeFormController"/> <bean name="/MsgBox/Alert.html" class="DM2.web.MsgBox.AlertController"></bean>--> <!-- <bean name="/career/ResumeForm/Resume_Submit.html" class="DM2.web.career.ResumeForm.Resume_SubmitController"></bean> --> <!--<bean name="/TestTags.html" class="DM2.web.TestTagsController"></bean>--> <!-- misc --> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/> <property name="prefix" value="/jsp/"/> <property name="suffix" value=".jsp"/> </bean> </beans>