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

Cannot instantiate interface org.springframework.boot.SpringApplicationRunListener : org.springframework.boot.context.event.EventPublishingRunListener #1582

Closed ebremer closed 2 years ago

ebremer commented 2 years ago

Project compiles using Ubuntu 20.X

using:
openjdk version "17.0.3" 2022-04-19
OpenJDK Runtime Environment GraalVM CE 22.2.0-dev (build 17.0.3+4-jvmci-22.1-b03)
OpenJDK 64-Bit Server VM GraalVM CE 22.2.0-dev (build 17.0.3+4-jvmci-22.1-b03, mixed mode, sharing)

reproduce with

git clone https://github.com/ebremer/embedded-spring-boot-keycloak-server.git
cd embedded-spring-boot-keycloak-server
git checkout nativebuild
mvn -Pundertow -DskipTests -Denforcer.skip=false clean spring-aot:generate package
cd embedded-keycloak-server-plain
target/keycloak

throws the error

Exception in thread "main" java.lang.IllegalArgumentException: Cannot instantiate interface org.springframework.boot.SpringApplicationRunListener : org.springframework.boot.context.event.EventPublishingRunListener
        at org.springframework.boot.SpringApplication.createSpringFactoriesInstances(SpringApplication.java:456)
        at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:173)
        at org.springframework.boot.SpringApplication.getRunListeners(SpringApplication.java:426)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:293)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1312)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1301)
        at com.github.thomasdarimont.keycloak.embedded.runner.Main.main(Main.java:11)
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.context.event.EventPublishingRunListener
        at java.lang.Class.forName(DynamicHub.java:1125)
        at org.springframework.util.ClassUtils.forName(ClassUtils.java:284)
        at org.springframework.boot.SpringApplication.createSpringFactoriesInstances(SpringApplication.java:449)
        ... 6 more
mhalbritter commented 2 years ago

You have to change <mode>native-agent</mode> to <mode>native</mode> in your pom.xml files. See this documentation.

Then #1576 will pop up:

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) ~[keycloak:2.6.6]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:577) ~[keycloak:5.3.18]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) ~[keycloak:2.6.6]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:740) ~[keycloak:2.6.6]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:415) ~[keycloak:2.6.6]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) ~[keycloak:2.6.6]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1312) ~[keycloak:2.6.6]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1301) ~[keycloak:2.6.6]
    at com.github.thomasdarimont.keycloak.embedded.runner.Main.main(Main.java:11) ~[keycloak:999-SNAPSHOT]
Caused by: java.lang.NoSuchMethodError: io.undertow.util.FastConcurrentDirectDeque.<init>()
    at io.undertow.util.ConcurrentDirectDeque.<clinit>(ConcurrentDirectDeque.java:45) ~[keycloak:2.2.16.Final]
    at io.undertow.server.handlers.cache.LRUCache.<init>(LRUCache.java:67) ~[na:na]
    at io.undertow.servlet.handlers.ServletPathMatches.<init>(ServletPathMatches.java:82) ~[keycloak:2.2.16.Final]
    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) ~[keycloak:2.6.6]
    at org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory.getWebServer(UndertowServletWebServerFactory.java:299) ~[keycloak:2.6.6]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:182) ~[keycloak:2.6.6]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:160) ~[keycloak:2.6.6]

But you apparently solved that already?

ebremer commented 2 years ago

Yeah, I thought I did and I missed the subtle difference between "native-agent" and "native". Once I made the above change this came back:

Spring Boot Version:  (v2.6.6)
Keycloak Version: (v@keycloak.version@)

2022-04-14 09:37:21.893  INFO 8098 --- [           main] c.g.t.keycloak.embedded.runner.Main      : Starting Main v999-SNAPSHOT using Java 17.0.3 on Corsair with PID 8098 (/mnt/d/projects/embedded-spring-boot-keycloak-server/embedded-keycloak-server-plain/target/keycloak started by erich in /mnt/d/projects/embedded-spring-boot-keycloak-server/embedded-keycloak-server-plain)
2022-04-14 09:37:21.893  INFO 8098 --- [           main] c.g.t.keycloak.embedded.runner.Main      : No active profile set, falling back to 1 default profile: "default"
2022-04-14 09:37:22.060  WARN 8098 --- [           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-14 09:37:22.063 ERROR 8098 --- [           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) ~[keycloak:2.6.6]
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:577) ~[keycloak:5.3.18]
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) ~[keycloak:2.6.6]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:740) ~[keycloak:2.6.6]
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:415) ~[keycloak:2.6.6]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) ~[keycloak:2.6.6]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1312) ~[keycloak:2.6.6]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1301) ~[keycloak:2.6.6]
        at com.github.thomasdarimont.keycloak.embedded.runner.Main.main(Main.java:11) ~[keycloak:999-SNAPSHOT]
Caused by: java.lang.NoSuchMethodError: io.undertow.util.FastConcurrentDirectDeque.<init>()
        at io.undertow.util.ConcurrentDirectDeque.<clinit>(ConcurrentDirectDeque.java:45) ~[keycloak:2.2.16.Final]
        at io.undertow.server.handlers.cache.LRUCache.<init>(LRUCache.java:67) ~[na:na]
        at io.undertow.servlet.handlers.ServletPathMatches.<init>(ServletPathMatches.java:82) ~[keycloak:2.2.16.Final]
        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) ~[keycloak:2.6.6]
        at org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory.getWebServer(UndertowServletWebServerFactory.java:299) ~[keycloak:2.6.6]
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:182) ~[keycloak:2.6.6]
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:160) ~[keycloak:2.6.6]
        ... 8 common frames omitted
mhalbritter commented 2 years ago

Then i'll reopen #1576 and close this one.