spring-attic / spring-native

Spring Native is now superseded by Spring Boot 3 official native support
https://docs.spring.io/spring-boot/docs/current/reference/html/native-image.html
Apache License 2.0
2.74k stars 356 forks source link

Problem when using aspect with annotation pointcut #1712

Closed agrancaric closed 1 year ago

agrancaric commented 1 year ago

Hello, I have a problem when using an aspect with annotation pointcut. It seems that the pointcut matches more that it should and causes an exception:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'projectingArgumentResolverBeanPostProcessor': Initialization of bean failed; nested exception is com.oracle.svm.core.jdk.UnsupportedFeatureError: Proxy class defined by interfaces [interface org.springframework.beans.factory.config.BeanPostProcessor, interface org.springframework.beans.factory.BeanFactoryAware, interface org.springframework.beans.factory.BeanClassLoaderAware] not found. Generating proxy classes at runtime is not supported. Proxy classes need to be defined at image build time by specifying the list of interfaces that they implement. To define proxy classes use -H:DynamicProxyConfigurationFiles=<comma-separated-config-files> and -H:DynamicProxyConfigurationResources=<comma-separated-config-resources> options.
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:628) ~[com.example.springnativepointcutexample.SpringNativePointcutExampleApplication:5.3.22]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[com.example.springnativepointcutexample.SpringNativePointcutExampleApplication:5.3.22]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[com.example.springnativepointcutexample.SpringNativePointcutExampleApplication:5.3.22]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[com.example.springnativepointcutexample.SpringNativePointcutExampleApplication:5.3.22]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[com.example.springnativepointcutexample.SpringNativePointcutExampleApplication:5.3.22]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:213) ~[com.example.springnativepointcutexample.SpringNativePointcutExampleApplication:5.3.22]
    at org.springframework.context.support.PostProcessorRegistrationDelegate.registerBeanPostProcessors(PostProcessorRegistrationDelegate.java:270) ~[na:na]
    at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:762) ~[com.example.springnativepointcutexample.SpringNativePointcutExampleApplication:5.3.22]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:567) ~[com.example.springnativepointcutexample.SpringNativePointcutExampleApplication:5.3.22]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:147) ~[na:na]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:734) ~[com.example.springnativepointcutexample.SpringNativePointcutExampleApplication:na]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:408) ~[com.example.springnativepointcutexample.SpringNativePointcutExampleApplication:na]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:308) ~[com.example.springnativepointcutexample.SpringNativePointcutExampleApplication:na]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306) ~[com.example.springnativepointcutexample.SpringNativePointcutExampleApplication:na]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295) ~[com.example.springnativepointcutexample.SpringNativePointcutExampleApplication:na]
    at com.example.springnativepointcutexample.SpringNativePointcutExampleApplication.main(SpringNativePointcutExampleApplication.java:14) ~[com.example.springnativepointcutexample.SpringNativePointcutExampleApplication:na]

when I add the mentioned interfaces to proxy-config.json another exception is thrown with more missing proxy entries etc. The issue seems to happen when I have also spring-boot-starter-data-jpa dependency (without it it works ok). What also works is a pointcut by full path execution (referencing the exact class and methods without annotation).
Not sure can I do anything from my side to fix it (the project attached is just an example and the original annotation and aspect are in a library so I would like to avoid users having to add a package)? The Graal and Java versions are:

Version info: 'GraalVM 22.2.0 Java 11 CE' Java version info: '11.0.16.1+1-LTS'

Thanks in advance for any help.

The example project: spring-native-pointcut-example.zip

toohandsome commented 1 year ago

same error

sdeleuze commented 1 year ago

Proper aspect support should come with Spring Framework 6 and Spring Boot 3 which are just around the corner. You can follow https://github.com/spring-projects/spring-framework/issues/28711 related issue.