When using spring-boot-docker-compose with a native image, the resulting native image doesn't start up:
Exception in thread "main" java.lang.IllegalArgumentException: Unable to instantiate factory class [org.springframework.boot.docker.compose.lifecycle.DockerComposeListener] for factory type [org.springframework.context.ApplicationListener]
at org.springframework.core.io.support.SpringFactoriesLoader$FailureHandler.lambda$throwing$0(SpringFactoriesLoader.java:651)classes/
at org.springframework.core.io.support.SpringFactoriesLoader$FailureHandler.lambda$handleMessage$3(SpringFactoriesLoader.java:675)
at org.springframework.core.io.support.SpringFactoriesLoader.instantiateFactory(SpringFactoriesLoader.java:231)
at org.springframework.core.io.support.SpringFactoriesLoader.load(SpringFactoriesLoader.java:206)
at org.springframework.core.io.support.SpringFactoriesLoader.load(SpringFactoriesLoader.java:160)
at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:462)
at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:458)
at org.springframework.boot.SpringApplication.<init>(SpringApplication.java:275)
at org.springframework.boot.SpringApplication.<init>(SpringApplication.java:253)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1305)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1294)
at com.example.demo.DemoApplication.main(DemoApplication.java:10)
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.docker.compose.lifecycle.DockerComposeListener
at java.base@17.0.6/java.lang.Class.forName(DynamicHub.java:1132)
at org.springframework.util.ClassUtils.forName(ClassUtils.java:284)
at org.springframework.core.io.support.SpringFactoriesLoader.instantiateFactory(SpringFactoriesLoader.java:224)
... 9 more
I've tested it with 3.1.1-SNAPSHOT. This only happens with Maven. With Gradle it's fine.
The dependency is declared like this:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-docker-compose</artifactId>
<optional>true</optional>
</dependency>
Reproducer: demo.zip
Comment From: wilkinsona
See https://github.com/spring-projects/spring-boot/issues/35548. It looks like the fix there didn't go far enough as it hasn't addressed the native image side of things.