Search code examples
spring-bootspring-securitygraalvm-native-imagespring-native

`@PreAuthorize` with spring-native triggers packaging error: `repeated interface: org.springframework.aop.SpringProxy`


I'm trying to build native images for spring-boot apps in a maven multi-module project.

As soon as I decorate a @Controller method with @PreAuthorize, native image generation fail with the message below.

Following spring-native samples, I tryed both with (as done in security-method-class-proxies) and without (as done in security-method) @AotProxyHint on application class, but this made no difference.

The error:

[INFO]     [creator]     Error: Error parsing dynamic proxy configuration in file:/workspace/META-INF/native-image/org.springframework.aot/spring-aot/proxy-config.json:
[INFO]     [creator]     java.lang.IllegalArgumentException: repeated interface: org.springframework.aop.SpringProxy
[INFO]     [creator]     Verify that the configuration matches the schema described in the -H:PrintFlags=+ output for option DynamicProxyConfigurationResources.
[INFO]     [creator]     Error: Use -H:+ReportExceptionStackTraces to print stacktrace of underlying exception
[INFO]     [creator]     Error: Image build request failed with exit status 1
[INFO]     [creator]     unable to invoke layer creator
[INFO]     [creator]     unable to contribute native-image layer
[INFO]     [creator]     error running build
[INFO]     [creator]     exit status 1
[INFO]     [creator]     ERROR: failed to build: exit status 1

Any clue why?


Solution

  • I figured out two things about this error:

    1. as soon as @PreAuthorize targets a class member (not an interface), configuration must provide an @AotProxyHint(targetClass = ..., proxyFeatures = ProxyBits.IS_STATIC) for this class
    2. there is bug on Windows about that declared in spring-native issues