在SpringBoot上使用SpringAOP,我有以下代码:
@Retention(RUNTIME)
@Target(TYPE)
public @interface MyAnnotation {
...
}
@MyAnnotation
public class MyClass {
...
}
@Aspect
@Component
public class MyAspect {
@After("@args(com.mypackage.MyAnnotation)")
public void myJoinPoint(JoinPoint jp) {
...
}
@After("@target(com.mypackage.MyAnnotation)")
public void myJoinPoint(JoinPoint jp) {
...
}
}
使用非注释切入点可以正常工作,但是仅在使用@target和@args时,我在尝试启动应用程序时遇到以下错误,有人可以帮助我吗?
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.boot.autoconfigure.web.ServerProperties org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration.properties; nested exception is java.lang.IllegalArgumentException: Can not set org.springframework.boot.autoconfigure.web.ServerProperties field org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration.properties to com.sun.proxy.$Proxy79
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:573) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
... 51 common frames omitted
Caused by: java.lang.IllegalArgumentException: Can not set org.springframework.boot.autoconfigure.web.ServerProperties field org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration.properties to com.sun.proxy.$Proxy79
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:167) ~[na:1.8.0_181]
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:171) ~[na:1.8.0_181]
at sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:81) ~[na:1.8.0_181]
at java.lang.reflect.Field.set(Field.java:764) ~[na:1.8.0_181]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:569) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
... 53 common frames omitted