[英]Spring AOP is not hijacking method with @Around annotation
Here is my pom.xml 这是我的pom.xml
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-integration</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jersey</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.6</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.52.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.2.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.mongodb.morphia</groupId>
<artifactId>morphia</artifactId>
<version>1.1.0-alpha2</version>
</dependency>
<dependency>
<groupId>ma.glasnost.orika</groupId>
<artifactId>orika-core</artifactId>
<version>1.4.6</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.aspectj/aspectjrt -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.8.9</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.aspectj/aspectjweaver -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.8.9</version>
</dependency>
</dependencies>
Here is my aspect class: 这是我的方面类:
@Aspect
@Service
public class AspectLogger {
static Logger logger = Logger.getLogger(AspectLogger.class);
@Around("execution(* com.xxx.model.bl.items.IPostProcessingService.postProcessingBulk(..))")
public void logAround(ProceedingJoinPoint joinPoint) throws Throwable {
logger.info("before!");
joinPoint.proceed(); //continue on the intercepted method
logger.info("after!");
}
}
PostProcessingService class: PostProcessingService类:
@Component
public class PostProcessingService implements IPostProcessingService {
...
}
I was trying to point out the execution to the interface and as well the the class it self, but still i didnt see any logging, as well was trying to set it to the controller that using the IPostProcessingService interface but still the same results 我试图指出接口的执行以及它本身的类,但仍然没有看到任何日志记录,也试图将其设置为使用IPostProcessingService接口的控制器,但结果仍然相同
I added as well to the application-conext: 我也添加到了应用程序扩展:
<aop:aspectj-autoproxy />
Did i miss something? 我错过了什么?
So the problem was that i miss 2 annotation in the AspectLogger
class 所以问题是我错过了
AspectLogger
类中的2个注释
@Aspect
@Configuration
@EnableAspectJAutoProxy
@Component
public class AspectLogger {
}
Now it is working 现在正在工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.