功能:

  日志记录,事务处理

简单描述:

  把几个类的共有代码,抽取到一个切片中,在运行时,动态地将代码切入到类的指定方法中。

使用方法:

  通过AOP代理,被调用到InvocationHandler类的invoker方法执行
  配置:被代理接口,被代理接口实现类,各类拦截器

代码实现:

 1 <!-- 配置事务管理器 -->
 2     <bean 
 3           class="org.springframework.orm.hibernate4.HibernateTransactionManager">
 4         <property name="sessionFactory" ref="sessionFactory"/>
 5     </bean>
 6 
 7     <!-- 配置事务的传播特性 -->
 8     <tx:advice >
 9         <tx:attributes>
10             <tx:method name="*" propagation="REQUIRED"/>
11         </tx:attributes>
12     </tx:advice>
13 
14     <!-- 那些类的哪些方法参与事务 -->
15     <aop:config>
16         <aop:pointcut 
17                       expression="execution(* com.selfpackage.service.*.*(..))"/>
18         <aop:advisor pointcut-ref="allServiceMethod" advice-ref="txAdvice"/>
19     </aop:config><!-- 配置事务管理器 -->
20     <bean 
21           class="org.springframework.orm.hibernate4.HibernateTransactionManager">
22         <property name="sessionFactory" ref="sessionFactory"/>
23     </bean>
24 
25     <!-- 配置事务的传播特性 -->
26     <tx:advice >
27         <tx:attributes>
28             <tx:method name="*" propagation="REQUIRED"/>
29         </tx:attributes>
30     </tx:advice>
31 
32     <!-- 那些类的哪些方法参与事务 -->
33     <aop:config>
34         <aop:pointcut 
35                       expression="execution(* com.selfpackage.service.*.*(..))"/>
36         <aop:advisor pointcut-ref="allServiceMethod" advice-ref="txAdvice"/>
37     </aop:config>

 四、IOC

IoC(控制反转),将类的创建和依赖关系写在配置文件里,由配置文件注入,实现了松耦合

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-12
  • 2022-12-23
  • 2021-09-23
  • 2021-12-20
  • 2021-11-14
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-06-22
  • 2021-07-17
  • 2021-07-25
  • 2022-02-04
  • 2022-01-04
相关资源
相似解决方案