zoukankan      html  css  js  c++  java
  • 使用Adivisor配置增强处理

    使用Adivisor配置增强处理

      实现步骤:

        1、通过MethodBeforeAdivice接口实现前置增强处理

     1 public class ServiceBeforeAdvisor implements MethodBeforeAdvice {
     2     private Logger logger = Logger.getLogger(ServiceBeforeAdvisor.class);
     3     @Override
     4     public void before(Method method, Object[] args, Object target)
     5             throws Throwable {
     6         logger.info("启动事务");
     7         logger.info("连接点对象:"+target.getClass().getSimpleName());
     8         logger.info("连接点方法:"+method.getName());
     9         logger.info("连接点方法参数:"+args[0]);
    10         
    11     }
    12     
    13 }

        2、使用<aop:advisor>标签织入增强处理

    1 //注意:advisor要放在aspect前面
    2     <bean id="userService" class="com.pb.service.UserService"></bean>
    3      <bean id="serviceBeforeAdvisor" class="com.pb.aop.ServiceBeforeAdvisor"></bean>
    4      <aop:config>
    5          <aop:pointcut expression="execution(public * com.pb.service.*.*(..))" 
                    id="servicePointcut"/> 6 <aop:advisor advice-ref="serviceBeforeAdvisor" pointcut-ref="servicePointcut"/> 7 </aop:config>

    测试类

    1 public class Test {
    2     public static void main(String[] args) {
    3         ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext
                        ("applicationContext.xml"); 4 UserService service = (UserService)context.getBean("userService"); 5 service.addUser(new User()); 6 } 7 }
  • 相关阅读:
    JS项目快速压缩(windows平台)
    Maven工程的POM继承
    Docker构建一个node镜像
    win10家庭版安装Docker for Windows
    linux,vim和bash命令小册
    vue文档阅读笔记——计算属性和侦听器
    nodejs的jekins部署
    `vue-router`的`History`模式下的项目发布
    花式图表,炫技时刻!PPT技能
    在创业之路上不断创新
  • 原文地址:https://www.cnblogs.com/xuerong/p/4922715.html
Copyright © 2011-2022 走看看