Closed mrchengxin closed 2 years ago
Interesting, happy to learn more about the data points yeah, I will have a deeper look to the repro.
For the record, Spring Framework 6 uses a different approach where generated code is rather co-located with their configuration infrastructure or target type. Unless those 2000 beans are in the same package space, this should fix the issue for you.
@mrchengxin would be interested to give Spring Framework 6 a try? The latest milestone is Spring Boot 3.0.0-M4
, but we're testing our smoke tests against the snapshot at the moment.
@snicoll Thank you for involving. It sounds promising. I would like to have a try with Spring Framework 6. Which version of Spring Native I should use along with Spring Boot 3.0.0-M4?
You don't need Spring Native at all with Spring Boot 3. I can see you are using Maven. Here is some initial doc, it's pretty light at this point. This repository provides a working example.
We're really be interested to get your feedback on your project based on Spring Boot 3.
I am closing this issue as it is expected to be handled by Spring Boot 3.
@mrchengxin If you have an issue with the upgrade please comment here, we will try to help.
Background: I'm trying to use Spring Native for a big Java application, which has more than 2,000 Spring beans. When I try to build a native image, the "code too large" error happened.
Exception log:
Sample project: demo.zip
Environment info: OS: Ubuntu 22.04 LTS JDK: GraalVM 22.1.0.r11 Maven: 3.8.6 Spring Boot: 2.7.0 Spring Native: 0.12.0
How to reproduce: Open the demo project, and execute this command:
or
Root cause: The generated
org.springframework.aot.ContextBootstrapInitializer#initialize(GenericApplicationContext context)
is too large.Tried solutions: I've tried to split the
initialize
method into small methods by this small fix: https://github.com/spring-projects-experimental/spring-native/compare/main...mrchengxin:spring-native:patch-1And it works.
Expectations: Could you look into this issue and fix it?
Probably applying Spring Native to such a big project with 2,000+ beans is not a good practice. But the experiment result turned out to be promising, for example, we found that memory consumption is reduced by 90% and the startup time is reduced to seconds compared to minutes. If you're interested in the result, I'm very glad to share it.