Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DevTools prevent startup in native image with ClassNotFoundException #35853

Closed
trisberg opened this issue Jun 12, 2023 · 4 comments
Closed

DevTools prevent startup in native image with ClassNotFoundException #35853

trisberg opened this issue Jun 12, 2023 · 4 comments
Assignees
Labels
theme: aot An issue related to Ahead-of-time processing type: regression A regression from a previous release
Milestone

Comments

@trisberg
Copy link
Member

Building and running web app as native image fails with java.lang.ClassNotFoundException after upgrade to Boot 3.1.0 from 3.0.5.

Sample project pom.xml for 3.0.x - https://github.com/trisberg/tanzu-java-web-app/blob/main/pom.xml
Same after update to Boot 3.1 - https://github.com/trisberg/tanzu-java-web-app/blob/boot31/pom.xml

The exception:

2023-06-11T09:52:54.937486462-04:00 Exception in thread "main" java.lang.IllegalArgumentException: Unable to instantiate factory class [org.springframework.boot.devtools.restart.RestartScopeInitializer] for factory type [org.springframework.context.ApplicationContextInitializer]
2023-06-11T09:52:54.937538656-04:00 	at org.springframework.core.io.support.SpringFactoriesLoader$FailureHandler.lambda$throwing$0(SpringFactoriesLoader.java:651)
2023-06-11T09:52:54.937546131-04:00 	at org.springframework.core.io.support.SpringFactoriesLoader$FailureHandler.lambda$handleMessage$3(SpringFactoriesLoader.java:675)
2023-06-11T09:52:54.937551864-04:00 	at org.springframework.core.io.support.SpringFactoriesLoader.instantiateFactory(SpringFactoriesLoader.java:231)
2023-06-11T09:52:54.937556622-04:00 	at org.springframework.core.io.support.SpringFactoriesLoader.load(SpringFactoriesLoader.java:206)
2023-06-11T09:52:54.937561230-04:00 	at org.springframework.core.io.support.SpringFactoriesLoader.load(SpringFactoriesLoader.java:160)
2023-06-11T09:52:54.937566131-04:00 	at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:462)
2023-06-11T09:52:54.937570912-04:00 	at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:458)
2023-06-11T09:52:54.937576500-04:00 	at org.springframework.boot.SpringApplication.<init>(SpringApplication.java:274)
2023-06-11T09:52:54.937581639-04:00 	at org.springframework.boot.SpringApplication.<init>(SpringApplication.java:253)
2023-06-11T09:52:54.937587087-04:00 	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1305)
2023-06-11T09:52:54.937591930-04:00 	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1294)
2023-06-11T09:52:54.937596813-04:00 	at com.example.springboot.Application.main(Application.java:17)
2023-06-11T09:52:54.937601696-04:00 Caused by: java.lang.ClassNotFoundException: org.springframework.boot.devtools.restart.RestartScopeInitializer
2023-06-11T09:52:54.937609439-04:00 	at java.base@17.0.6/java.lang.Class.forName(DynamicHub.java:1132)
2023-06-11T09:52:54.937614517-04:00 	at org.springframework.util.ClassUtils.forName(ClassUtils.java:284)
2023-06-11T09:52:54.937619527-04:00 	at org.springframework.core.io.support.SpringFactoriesLoader.instantiateFactory(SpringFactoriesLoader.java:224)
2023-06-11T09:52:54.937624712-04:00 	... 9 more
@trisberg
Copy link
Member Author

Possibly related issue #33760

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jun 12, 2023
@mhalbritter
Copy link
Contributor

Can be reproduced with a project from start.spring.io with devtools and native dependency. No other changes needed.

@mhalbritter mhalbritter added this to the 3.1.x milestone Jun 12, 2023
@mhalbritter mhalbritter added type: regression A regression from a previous release theme: aot An issue related to Ahead-of-time processing and removed status: waiting-for-triage An issue we've not yet triaged labels Jun 12, 2023
@ninijule
Copy link

ninijule commented Jun 15, 2023

Hello,

Currently, I'm new to use GraalVm but i have exactly the same problem as @mhalbritter.

in the pom i got this for dev-tools.

 <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>

I personally got this error

 .\demo.exe
Exception in thread "main" java.lang.IllegalArgumentException: Unable to instantiate factory class [org.springframework.boot.devtools.restart.RestartScopeInitializer] for factory type [org.springframework.context.ApplicationContextInitializer]
        at org.springframework.core.io.support.SpringFactoriesLoader$FailureHandler.lambda$throwing$0(SpringFactoriesLoader.java:651)
        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:274)
        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 fr.beutininformatique.backend.demo.BackEndApplication.main(BackEndApplication.java:12)
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.devtools.restart.RestartScopeInitializer
        at org.graalvm.nativeimage.builder/com.oracle.svm.core.hub.ClassForNameSupport.forName(ClassForNameSupport.java:123)
        at org.graalvm.nativeimage.builder/com.oracle.svm.core.hub.ClassForNameSupport.forName(ClassForNameSupport.java:87)
        at java.base@17.0.7/java.lang.Class.forName(DynamicHub.java:1322)
        at java.base@17.0.7/java.lang.Class.forName(DynamicHub.java:1311)
        at org.springframework.util.ClassUtils.forName(ClassUtils.java:284)
        at org.springframework.core.io.support.SpringFactoriesLoader.instantiateFactory(SpringFactoriesLoader.java:224)
        ... 9 more

don't know if it will help :|

Good luck !

@wilkinsona
Copy link
Member

The change in behavior is due to #35548. The changes made for that issue mean that DevTools is no longer included on the classpath during AOT processing. As a result, no reflection hints are generated for org.springframework.boot.devtools.restart.RestartScopeInitializer which is registered via spring.factories. We can't control the native image classpath so DevTools is present and is included in the image. This results in its spring.factories file being found and an attempt made to load org.springframework.boot.devtools.restart.RestartScopeInitializer. It fails due to the aforementioned lack of reflection hints.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme: aot An issue related to Ahead-of-time processing type: regression A regression from a previous release
Projects
None yet
Development

No branches or pull requests

5 participants