标签:turn getbean 配置 new setname spring bean aop ring
实体类
public class Dog {
private String name;
public void say(){
System.out.println(name+"在汪汪叫");
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
切面类
@Aspect
public class MyAspect {
@Before("execution(* com.how2java.pojo..*(..))")
public void before(){
System.out.println("前置通知");
}
}
配置文件
<!-- 开启Aspect功能-->
<aop:aspectj-autoproxy/>
<bean id="dog" class="com.how2java.pojo.Dog"/>
<!-- 定义aspect类-->
<bean name="myAspect" class="com.how2java.aspect.MyAspect"/>
测试
ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext.xml");
Dog dog=(Dog)context.getBean("dog");
System.out.println(dog.getClass());
dog.say();
result:
class com.how2java.pojo.Dog$$EnhancerBySpringCGLIB$$c5373749
前置通知
null在汪汪叫
标签:turn getbean 配置 new setname spring bean aop ring
原文地址:https://www.cnblogs.com/zhuob/p/12288470.html