spring切面:注解:最终增强

1.最终增强

package aop;

import org.apache.log4j.Logger;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;

@Aspect
public class AfterAnno {
	private static final Logger log = Logger.getLogger(AfterAnno.class);
	@After("execution(* biz.impl.*.*(..))")
	public void after(JoinPoint jp){
		System.out.println("进入最终增强");
		log.info(jp.getSignature().getName()+"最终方法");
	}
}

2.applicationContext.xml配置文件



 
 
	
	
	
	
	
    
      
    
   
   
 
       
       
       
       
          
             
                
                    u1
                
                tom
             
              
                
                    u2
                
                jack
             
          
       
       
          
              Tom
              jack
              LiLei
              LiLei
          
       
       
          
              Tom
              jack
              LiLei1
              LiLei2
          
       
       
          
              Tom
              jack
              LiLei
              LiLei
          
       
       
        
       
      
    

3.user.impl/UserDaoImpl类

package dao.impl;

import javax.management.RuntimeErrorException;

import dao.UserDao;
import entity.User;

public class UserDaoImpl implements UserDao {

	@Override
	public User findUser() {
		System.out.println("===========Dao层查询User 1==============");
		User u=new User("Tom",22);
		throw new RuntimeException("出现异常");
		//return u;
	}

}

4.Test类

package test;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import entity.User;

import biz.UserBiz;
import biz.impl.UserBizImpl;

import ioc.HelloWorld;

public class TestMain {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		//加载spring容器,解析配置文件
		ApplicationContext ac=new ClassPathXmlApplicationContext("applicationContext.xml");
         /*HelloWorld helloWorld=(HelloWorld) ac.getBean("helloWorld");
         System.out.println("你好:"+helloWorld.getName()+","+helloWorld.getSet().size()+","+helloWorld.getMap().get("u1"));*/
		 UserBiz userBiz=(UserBiz) ac.getBean("userBiz");
		 User u= userBiz.getUser(101);
		 System.out.println(u.getUname()+","+u.getAge());
	}

}

spring切面:注解:最终增强_第1张图片

你可能感兴趣的:(Spring)