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 355 forks source link

java.lang.NoSuchMethodError: io.undertow.util.FastConcurrentDirectDeque.<init>() #1576

Closed ebremer closed 2 years ago

ebremer commented 2 years ago

I was able to compile a Spring Boot Project of mine that uses Undertow.

Spring 2.6.6. spring-aot-maven-plugin 0.11.4 native-maven-plugin 0.9.11

During compiling, the following was issued:

Warning: Could not register complete reflection metadata for io.undertow.protocols.alpn.JettyAlpnProvider. Reason(s): java.lang.NoClassDefFoundError: org/eclipse/jetty/alpn/ALPN$ClientProvider
'''
The compiling completed successfully, but on startup, it crashes with the following:

'''
2022-04-07 09:09:22.940  WARN 9548 --- [           main] w.s.c.ServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is java.lang.NoSuchMethodError: io.undertow.util.FastConcurrentDirectDeque.<init>()
2022-04-07 09:09:22.941 ERROR 9548 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is java.lang.NoSuchMethodError: io.undertow.util.FastConcurrentDirectDeque.<init>()
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:163) ~[na:na]
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:577) ~[na:na]
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) ~[na:na]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:740) ~[halcyon:2.6.6]
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:415) ~[halcyon:2.6.6]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) ~[halcyon:2.6.6]
        at is.halcyon.imagebox.Main.main(Main.java:190) ~[halcyon:0.0.0]
Caused by: java.lang.NoSuchMethodError: io.undertow.util.FastConcurrentDirectDeque.<init>()
        at io.undertow.util.ConcurrentDirectDeque.<clinit>(ConcurrentDirectDeque.java:45) ~[na:na]
        at io.undertow.server.handlers.cache.LRUCache.<init>(LRUCache.java:67) ~[na:na]
        at io.undertow.servlet.handlers.ServletPathMatches.<init>(ServletPathMatches.java:82) ~[na:na]
        at io.undertow.servlet.core.DeploymentImpl.<init>(DeploymentImpl.java:95) ~[na:na]
        at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:151) ~[na:na]
        at org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory.createManager(UndertowServletWebServerFactory.java:330) ~[na:na]
        at org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory.getWebServer(UndertowServletWebServerFactory.java:299) ~[na:na]
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:182) ~[na:na]
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:160) ~[na:na]
        ... 6 common frames omitted
mhalbritter commented 2 years ago

If you'd like us to spend some time investigating, please take the time to provide a complete minimal sample (something that we can unzip or git clone, build, and deploy) that reproduces the problem.

ebremer commented 2 years ago

The project builds an embedded Keycloak server using Spring Boot.

git clone https://github.com/ebremer/embedded-spring-boot-keycloak-server.git
cd embedded-spring-boot-keycloak-server
git checkout nativebuild
mvn -X -DskipTests -Pundertow clean install
cd embedded-keycloak-server-plain
mvn -X -DskipTests -Pnative clean package

then run "target\keycloak" Under Ubuntu 20, it will build and then running it will generate the error:

[java.lang.NoSuchMethodError: io.undertow.util.FastConcurrentDirectDeque.<init>()](https://github.com/spring-projects-experimental/spring-native/issues/1576#)

Under Windows 11, the build fails with the following error:

========================================================================================================================
GraalVM Native Image: Generating 'keycloak'...
========================================================================================================================
[1/7] Initializing...                                                                                   (13.4s @ 0.21GB)
Warning: Could not register org.springframework.boot.actuate.health.ReactiveHealthEndpointWebExtension: allPublicMethods for reflection. Reason: java.lang.NoClassDefFoundError: reactor/core/publisher/Mono.
 Version info: 'GraalVM 22.0.0.2 Java 17 CE'
[2/7] Performing analysis...  [*********]                                                               (65.5s @ 5.72GB)
10:46:00.457 [main] DEBUG org.jboss.logging - Logging Provider: org.jboss.logging.Log4j2LoggerProvider
Warning: Could not register complete reflection metadata for org.springframework.aop.aspectj.autoproxy.AspectJAwareAdvisorAutoProxyCreator. Reason(s): java.lang.NoClassDefFoundError: org/aspectj/util/PartialOrder$PartialComparable
Warning: Could not register complete reflection metadata for org.springframework.boot.actuate.health.ReactiveHealthEndpointWebExtension. Reason(s): java.lang.NoClassDefFoundError: reactor/core/publisher/Mono
Warning: Could not register complete reflection metadata for org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator. Reason(s): java.lang.NoClassDefFoundError: org/aspectj/util/PartialOrder$PartialComparable
Warning: Could not register complete reflection metadata for io.undertow.protocols.alpn.JettyAlpnProvider. Reason(s): java.lang.NoClassDefFoundError: org/eclipse/jetty/alpn/ALPN$ClientProvider
  26,836 (91.67%) of 29,274 classes reachable
  45,955 (80.58%) of 57,032 fields reachable
 129,391 (62.78%) of 206,108 methods reachable
   1,118 classes,   362 fields, and 4,100 methods registered for reflection
      82 classes,    78 fields, and    67 methods registered for JNI access
[3/7] Building universe...                                                                               (4.7s @ 4.20GB)
[4/7] Parsing methods...      [*]                                                                        (1.4s @ 6.42GB)
[5/7] Inlining methods...     [*****]                                                                    (4.9s @ 4.99GB)
[6/7] Compiling methods...    [****]                                                                    (15.7s @ 5.84GB)
[7/7] Creating image...
Fatal error: com.oracle.svm.core.util.VMError$HostedError: should not reach here
        at com.oracle.svm.core.util.VMError.shouldNotReachHere(VMError.java:64)
        at com.oracle.svm.hosted.jdk.JNIRegistrationSupport.makeShimDLL(JNIRegistrationSupport.java:256)
        at com.oracle.svm.hosted.jdk.JNIRegistrationSupport.makeShimDLLs(JNIRegistrationSupport.java:230)
        at com.oracle.svm.hosted.jdk.JNIRegistrationSupport.afterImageWrite(JNIRegistrationSupport.java:175)
        at com.oracle.svm.hosted.NativeImageGenerator.lambda$doRun$8(NativeImageGenerator.java:680)
        at com.oracle.svm.hosted.FeatureHandler.forEachFeature(FeatureHandler.java:74)
        at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:680)
        at com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:494)
        at com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:426)
        at com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:587)
        at com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:126)
        at com.oracle.svm.hosted.NativeImageGeneratorRunner$JDK9Plus.main(NativeImageGeneratorRunner.java:617)
------------------------------------------------------------------------------------------------------------------------
                       12.4s (10.3% of total time) in 78 GCs | Peak RSS: 11.12GB | CPU load: 8.51
------------------------------------------------------------------------------------------------------------------------
Produced artifacts:
 D:\projects\embedded-spring-boot-keycloak-server\embedded-keycloak-server-plain\target\keycloak.exe (executable)
 D:\projects\embedded-spring-boot-keycloak-server\embedded-keycloak-server-plain\target\awt.dll (jdk_lib)
 D:\projects\embedded-spring-boot-keycloak-server\embedded-keycloak-server-plain\target\javajpeg.dll (jdk_lib)
 D:\projects\embedded-spring-boot-keycloak-server\embedded-keycloak-server-plain\target\lcms.dll (jdk_lib)
 D:\projects\embedded-spring-boot-keycloak-server\embedded-keycloak-server-plain\target\keycloak.build_artifacts.txt
========================================================================================================================
Failed generating 'keycloak' after 1m 59s.
ebremer commented 2 years ago

closing this issue as I found multiple mistakes on my part with supported versions. I'm getting a new error which is consistent on both windows and linux builds, but I will open up a new issue if I cannot resolve it myself.

mhalbritter commented 2 years ago

Seems like we are missing some configuration for undertow.

sdeleuze commented 2 years ago

Yeah this is expected, only Tomcat is supported for now, see #249 related issue and support documentation.

This should probably fixed in Spring Boot 3 timeframe, so I will close this issue as duplicate of #249.