此版本仍在开发中,尚未被视为稳定版本。对于最新的稳定版本,请使用 Spring Framework 6.2.0! |
启用 @AspectJ 支持
要在 Spring 配置中使用 @AspectJ 方面,您需要启用 Spring 对 基于 @AspectJ 方面配置 Spring AOP 并基于 无论他们是否受到这些方面的建议。自动代理是指,如果 Spring 确定 bean 由一个或多个 aspect 通知,则它会自动生成 该 bean 的代理,用于拦截方法调用并确保 Advice 运行 根据需要。
可以通过编程或 XML 配置启用 @AspectJ 支持。在任一
case 中,您还需要确保 AspectJ 的org.aspectj:aspectjweaver
library 位于
classpath (版本 1.9 或更高版本)。
-
Java
-
Kotlin
-
Xml
@Configuration
@EnableAspectJAutoProxy
public class ApplicationConfiguration {
}
@Configuration
@EnableAspectJAutoProxy
class ApplicationConfiguration
<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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop
https://www.springframework.org/schema/aop/spring-aop.xsd">
<aop:aspectj-autoproxy />
</beans>