Ошибка SpringAOP с @Component и @args или @target при запуске с Springboot - PullRequest
0 голосов
/ 11 октября 2018

У меня есть следующий код, использующий SpringAOP в SpringBoot:

@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) {
        ...        
    }

}

С pointcut без аннотации это работает, но только с @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
...