Hi,
I’m running into a problem with a pretty big Spring project (about 18,000 beans). When I build with AOT processing turned on, the build crashes with:
/<_REDACTED_>/AotProcessingApplication__BeanFactoryRegistrations.java:18253: error: too many constants
public class AotProcessingApplication__BeanFactoryRegistrations {
(The generated file is massive—tens of thousands of lines.)
A couple extra details:
- The project has a huge number of Spring beans/configs.
- From what I can tell, the generated AotProcessingApplication__BeanFactoryRegistrations file is blowing past Java’s class constant pool limit.
I searched around and found #33126, which describes a similar situation, but that seemed to be hitting method size limits rather than constant pool limits.
Here’s my setup: - Spring: 6.2.7 - Spring Boot: 3.5.0 - JDK: 21 - Build: Gradle
Is there any way to avoid hitting this limit? Can the generated BeanFactory registration file be split up, or is there a recommended workaround for big projects like this?
Right now I'm trying to break up the generated file using a Python script as a Gradle post-task, but it is pretty hacky.
Thanks a lot for any pointers!
Comment From: sbrannen
Indeed, that is problematic.
I modified the applyToWithLargeBeanDefinitionsCreatesSlices() test in BeanRegistrationsAotContributionTests so that it attempts to process 18_000 beans, and that fails as follows.
org.springframework.core.test.tools.CompilationException: Unable to compile source
too many constants /com/example/TestTarget__BeanFactoryRegistrations.java 11:8
---- source: com/example/TestTarget__BeanFactoryRegistrations.java
We'll have to see if we can expand on the strategy used in #33126.
Though, I suppose we might end up having to find a way to split the source file into multiple source files.
Comment From: snicoll
@manasjoshi14 thanks for the report. If you can try the snapshot before the release next month, that'd be much appreciated.