Skip to content

Default spring.aot.repositories.enabled to true when AOT is active #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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

HyunSangHan
Copy link

@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
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
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
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
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