-
Notifications
You must be signed in to change notification settings - Fork 40.8k
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
Use of @EntityScan causes AOT instance supplier code generation error #34371
Comments
This is an intentional change in Spring Framework |
Hi @scottfrederick , thanks for quickly reply. So that means we are unable to build native images when application uses Spring Data on 3.0.3? Do you know if It will be "fixed" in future Spring boot/Spring releases? Thank you. |
I wonder if we've missed replacing this code: Lines 173 to 176 in 8a9ea2b
That said, our JPA smoke test is passing at the moment. Perhaps the use of custom packages in the sample is the cause? |
Thanks for the sample @trcoelho, I should have looked more closely at it before closing the issue. The presence of the |
Thinking about this some more, I don't think In Spring Framework 6.0.4, custom instance suppliers were silently ignored. This means that in Boot 3.0.2, the entity scan packages are empty. That doesn't actually matter because the persistent types have been found at build time and recorded in the /**
* Get the bean instance for 'persistenceManagedTypes'.
*/
private static PersistenceManagedTypes getPersistenceManagedTypesInstance() {
List<String> managedClassNames = List.of("com.example.entity.Authentication", "com.example.entity.IdentifiableEntity");
List<String> managedPackages = List.of();
return PersistenceManagedTypes.of(managedClassNames, managedPackages);
}
/**
* Get the bean definition for 'persistenceManagedTypes'
*/
public static BeanDefinition getPersistenceManagedTypesBeanDefinition() {
Class<?> beanType = PersistenceManagedTypes.class;
RootBeanDefinition beanDefinition = new RootBeanDefinition(beanType);
beanDefinition.setPrimary(true);
beanDefinition.setInstanceSupplier(PersistenceManagedTypesConfiguration__BeanDefinitions::getPersistenceManagedTypesInstance);
return beanDefinition;
} The change in Framework 6.0.5 means that the instance supplier is no longer ignored and causes a failure instead. I think we can just exclude the bean during AOT processing. |
@trcoelho You can work around the problem with Spring Boot 3.0.3 by using a package com.example;
import org.springframework.beans.factory.aot.BeanRegistrationExcludeFilter;
import org.springframework.beans.factory.support.RegisteredBean;
import org.springframework.boot.autoconfigure.domain.EntityScanPackages;
class EntityScanExcludeFilter implements BeanRegistrationExcludeFilter {
@Override
public boolean isExcludedFromAotProcessing(RegisteredBean registeredBean) {
return registeredBean.getBeanClass().equals(EntityScanPackages.class);
}
} Such filters are registered in a file named
|
Thanks @wilkinsona ! Is this will be fixed on next spring boot release? Thank you. |
We hope so, yes. |
Hi all. FYI Have tested on Spring Boot 3.0.4 and we still got same issue. :( Thank you. |
@trcoelho The issue is still open, indicating that we haven't attempted to fix this problem yet. When we have a fix the issue will be closed and assigned to a specific version milestone. |
fyi: The issue is still occuring while running tests with |
@CasaSky Are you able to open a new issue and provide a reproducer? |
Hello!
After updating to Spring boot 3.0.3, native images are showing up the following exception:
When run
mvn -Pnative spring-boot:build-image
.Curiously it did not happen on Spring boot 3.0.2.
I've attached these two projects that happens what I explained.
spring-boot-examples.zip
Am I missing some configuration or is this a bug?
Thanks in advance.
The text was updated successfully, but these errors were encountered: