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 }
  • 相关阅读:
    控件的用法ComboBox;RadionButton;Timer;DataGridView
    echo.js实现图片延迟加载,
    取消移动端a标签点击变色
    JS实现上传图片实时预览
    Myeclipse6.0安装svn插件
    警告: Parameters: Character decoding failed. Parameter skipped
    jsp到action 传递url时中文出现乱码
    java面试题
    myeclipse中hibernate出错
    java中abstract的用法
  • 原文地址:https://www.cnblogs.com/xuerong/p/4922715.html
Copyright © 2011-2022 走看看