Declarative transaction demarcation

xml 代码
  1. <beans>  
  2.      ...   
  3.   
  4.    <bean id="myTxManager" class="org.springframework.orm.hibernate.HibernateTransactionManager">  
  5.      <property name="sessionFactory" ref="mySessionFactory"/>  
  6.    </bean>  
  7.   
  8.    <bean id="myTxInterceptor"  
  9.      class="org.springframework.transaction.interceptor.TransactionInterceptor">  
  10.      <property name="transactionManager" ref="myTxManager"/>  
  11.      <property name="transactionAttributeSource">  
  12.        <value>  
  13.          product.ProductService.increasePrice*=PROPAGATION_REQUIRED   
  14.          product.ProductService.someOtherBusinessMethod=PROPAGATION_MANDATORY  
  15.        </value>  
  16.      </property>  
  17.    </bean>  
  18.   
  19.    <bean id="myProductServiceTarget" class="product.ProductServiceImpl">  
  20.      <property name="productDao" ref="myProductDao"/>  
  21.    </bean>  
  22.   
  23.    <bean id="myProductService" class="org.springframework.aop.framework.ProxyFactoryBean">  
  24.      <property name="proxyInterfaces">  
  25.        <value>product.ProductService</value>  
  26.      </property>  
  27.      <property name="interceptorNames">  
  28.        <list>  
  29.          <value>myTxInterceptor</value>  
  30.          <value>myProductServiceTarget</value>  
  31.        </list>  
  32.      </property>  
  33.    </bean>  
  34.   
  35. </beans>  

 

java代码

  1. public class ProductServiceImpl implements ProductService {   
  2.   
  3.      private ProductDao productDao;   
  4.   
  5.      public void setProductDao(ProductDao productDao) {   
  6.          this.productDao = productDao;   
  7.      }   
  8.   
  9.      public void increasePriceOfAllProductsInCategory(final String category) {   
  10.          List productsToChange = this.productDAO.loadProductsByCategory(category);   
  11.          ...   
  12.      }   
  13.   
  14.      ...   
  15. }   

你可能感兴趣的:(AOP,bean,Hibernate,xml,orm)