When I declared bean as a class in configuration Aspect worked as expected, but when as an interface - application failed.

I prepared a small demo to show the issue: demo_aspect_native.

Steps:

  • provide service bean as class: bean declaration
  • run application as regular app
  • GET /home and see that Aspect works: "From aspect: Welcome!"
  • stop app
  • build native application: mvn -Pnative native:compile
  • run app: ./target/demo
  • GET /home and see that Aspect works: "From aspect: Welcome!"
  • change service bean declaration from class to interface (from DefaultHomeService to HomeService in bean declaration)
  • build native application: mvn -Pnative native:compile
  • run app: ./target/demo: application doesn't start with error:
Caused by: java.lang.IllegalArgumentException: error Type referred to is not an annotation type: com$example$demo$logic$AspectAnnotation
        at org.aspectj.weaver.tools.PointcutParser.parsePointcutExpression(PointcutParser.java:319) ~[demo:na]
        at org.springframework.aop.aspectj.AspectJExpressionPointcut.buildPointcutExpression(AspectJExpressionPointcut.java:222) ~[na:na]
        at org.springframework.aop.aspectj.AspectJExpressionPointcut.obtainPointcutExpression(AspectJExpressionPointcut.java:193) ~[na:na]
        at org.springframework.aop.aspectj.AspectJExpressionPointcut.getClassFilter(AspectJExpressionPointcut.java:172) ~[na:na]

In my real project (with almost the same configuration) when I declared a bean as an interface application started. but aspect doesn't work. Thanks!

Comment From: wilkinsona

Support for aspects in a native image is a Spring Framework feature. Please review https://github.com/spring-projects/spring-framework/issues/28711 which may be relevant here. If you feel that you have a different problem that is not covered by 28711, please open a new Spring Framework issue.