Skip to content

Generated __BeanFactoryRegistrations.java file contains "too many constants" when building with many beans #35044

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

Open
manasjoshi14 opened this issue Jun 13, 2025 · 1 comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) theme: aot An issue related to Ahead-of-time processing type: bug A general bug
Milestone

Comments

@manasjoshi14
Copy link

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!

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jun 13, 2025
@sbrannen sbrannen added in: core Issues in core modules (aop, beans, core, context, expression) theme: aot An issue related to Ahead-of-time processing labels Jun 13, 2025
@sbrannen sbrannen changed the title __BeanFactoryRegistrations.java generated file too large: "too many constants" error when building with many beans Generated __BeanFactoryRegistrations.java file contains "too many constants" when building with many beans Jun 13, 2025
@sbrannen
Copy link
Member

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.

@sbrannen sbrannen added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jun 13, 2025
@sbrannen sbrannen added this to the 6.2.x milestone Jun 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) theme: aot An issue related to Ahead-of-time processing type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants