Spring事務處理

<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
      <property name="dataSource" ref="dynamicDataSource" />
    <property name="hibernateProperties">
<props>
    <prop key="hibernate.dialect">${hibernate.dialect}</prop>
    <prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
    <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
    <prop key="hibernate.current_session_context_class">org.springframework.orm.hibernate4.SpringSessionContext</prop>
</props>
</property>
<property name="mappingLocations">
    <value>classpath:com/dayangit/**/*.hbm.xml </value>
</property>
</bean>

<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory"></property>
</bean>

<!-- 配置事務通知屬性 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<!-- 定義事務傳播屬性 -->
  <tx:attributes>
    <tx:method name="insert*" propagation="REQUIRED" />
    <tx:method name="update*" propagation="REQUIRED" />
    <tx:method name="edit*" propagation="REQUIRED" />
    <tx:method name="save*" propagation="REQUIRED" />
    <tx:method name="add*" propagation="REQUIRED" />
    <tx:method name="new*" propagation="REQUIRED" />
    <tx:method name="set*" propagation="REQUIRED" />
    <tx:method name="remove*" propagation="REQUIRED" />
    <tx:method name="delete*" propagation="REQUIRED" />
    <tx:method name="get*" propagation="REQUIRED" read-only="true" />
    <tx:method name="find*" propagation="REQUIRED" read-only="true" />
    <tx:method name="load*" propagation="REQUIRED" read-only="true" />
    <tx:method name="*" propagation="REQUIRED" read-only="true" />
  </tx:attributes>
</tx:advice>
<aop:config>
    <aop:pointcut id="serviceOperation" expression="execution(* com.dayangit..*Service*.*(..))" />
    <aop:pointcut id="managerOperation" expression="execution(* com.dayangit..*Manager*.*(..))" />
    <aop:advisor advice-ref="txAdvice" pointcut-ref="serviceOperation" />
    <aop:advisor advice-ref="txAdvice" pointcut-ref="managerOperation" />
</aop:config>java

<!-- 啓動註解驅動的Spring MVC功能,註冊請求url和註解POJO類方法的映射-->
<mvc:annotation-driven>
<!-- 處理responseBody 裏面日期類型 -->
<mvc:message-converters>
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<property name="objectMapper">
<bean class="com.fasterxml.jackson.databind.ObjectMapper">
<property name="dateFormat">
<bean class="java.text.SimpleDateFormat">
<constructor-arg type="java.lang.String" value="yyyy-MM-dd HH:mm:ss" />
</bean>
</property>
</bean>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>git

相關文章
相關標籤/搜索