Skip to content

Enable AOT repository generation by default #3904

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

Closed
wants to merge 4 commits into from

Conversation

HyunSangHan
Copy link
Contributor

@HyunSangHan HyunSangHan commented May 30, 2025

Resolves: #3899

Currently, to leverage AOT optimized repositories on the JVM with Spring Data JPA, users need to explicitly set both spring.aot.enabled=true and spring.aot.repositories.enabled=true.

This change updates the behavior so that if Spring Framework's AOT processing is active (e.g., spring.aot.enabled=true is set, or the application is being prepared for a native image), Spring Data JPA's AOT repository generation (spring.aot.repositories.enabled) will also be enabled by default.

Copy link
Member

@mp911de mp911de left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for submitting a pull request. I left a few comments so you can improve your test code.


GenericApplicationContext context = new GenericApplicationContext();

System.setProperty(AotDetector.AOT_ENABLED, "true");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting system properties can be achieved via @SetSystemProperty(…) to avoid leaking system properties state if the test fails.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mp911de
Thank you for your feedback! I completely understand your point and I agree with you.
To use @SetSystemProperty(…) and @ClearSystemProperty, we need to add the junit-pioneer dependency.
Do you think it would be a good idea to include junit-pioneer in this project?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have it already in Spring Data MonoDB, feel free to include it in JPA as well.

}

@Test // GH-3899
void repositoryProcessorShouldNotEnableAotRepositoriesByDefaultWhenAotIsDisabled() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could use @ClearSystemProperty here

System.setProperty(AotDetector.AOT_ENABLED, "true");

try {
JpaRepositoryContributor contributor = new JpaRepositoryConfigExtension.JpaRepositoryRegistrationAotProcessor()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This snippet could be extracted into a utility method within the test class to not repeat ourselves.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. I created a private method and refactored these.

System.setProperty(AotDetector.AOT_ENABLED, "true");

try {
MockPropertySource propertySource = new MockPropertySource()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be handled by system properties as well as GenericApplicationContext creates StandardEnvironment that utilizes system properties and system environment for property sources. That would simplify the test arrangement.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I changed to use SetSystemProperty for this!

@mp911de mp911de added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Jun 2, 2025
@HyunSangHan HyunSangHan requested a review from mp911de June 3, 2025 17:49
@mp911de mp911de changed the title Default spring.aot.repositories.enabled to true when AOT is active Enable AOT repository generation by default Jul 11, 2025
@mp911de mp911de self-assigned this Jul 11, 2025
@mp911de mp911de added this to the 4.0 M4 (2025.1.0) milestone Jul 11, 2025
@mp911de
Copy link
Member

mp911de commented Jul 11, 2025

Thank you for your contribution. That's merged and polished now.

@mp911de mp911de closed this Jul 11, 2025
mp911de pushed a commit that referenced this pull request Jul 11, 2025
Signed-off-by: Hyunsang Han <[email protected]>
Original pull request: #3904
Closes #3899
mp911de added a commit that referenced this pull request Jul 11, 2025
Refine documentation wording. Use build-managed JUnit pioneer version property. Use Commons-infrastructure for checking whether AOT repositories are enabled.

Original pull request: #3904
See #3899
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enable AOT repositories by default
3 participants