您看,当我点击运行的时候为什么没有织入呀
按照逻辑应该是先输出"我是前置通知"然后输出"输出了!"__
我的目标类Test1目标类有连接点show方法
package com.experience.test;
import org.springframework.stereotype.Repository;
import org.testng.annotations.Test;
/**
* @author zhangsan
*/
@Repository
public class Test1 {
@Test
public void show(){
System.out.println("输出了!");
}
}
切入类和通知
package com.experience.aspect;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
@Component
@Aspect
public class MyAspect {
@Pointcut("execution(void com.experience.test.Test1.show())")
private void method(){}
@Before("method() ")
public void show(){
System.out.println("我是前置通知!");
}
}
配置文件
<?xml version="1.0" encoding="UTF-8" ?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
https://www.springframework.org/schema/aop/spring-aop.xsd">
<!-- 开启注解扫描,扫描包-->
<context:component-scan base-package="com.experience.service"/>
<context:component-scan base-package="com.experience.test"/>
<context:component-scan base-package="com.experience.aspect"/>
<aop:aspectj-autoproxy/>
</beans>