-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Open
Labels
theme: aotAn issue related to Ahead-Of-Time processingAn issue related to Ahead-Of-Time processingtype: bugA general bugA general bug
Milestone
Description
spring-data-mongodb-aot-multiple-mongo-operations.zip
Description: I am using Spring Boot 4 and Spring Data MongoDB 5 with multiple MongoTemplate beans defined (one marked @primary, another named mongoTemplateDB2).
When running AOT processing, the generated code for repository fragments incorrectly fetches the MongoOperations bean by type. This causes it to always inject the @primary bean, even for repositories configured to use the secondary database.
In the generated __BeanDefinitions.java file:
beanDefinition.getPropertyValues().addPropertyValue("repositoryFragmentsFunction", new RepositoryFactoryBeanSupport.RepositoryFragmentsFunction() {
public RepositoryComposition.RepositoryFragments getRepositoryFragments(
BeanFactory beanFactory, RepositoryFactoryBeanSupport.FragmentCreationContext context) {
MongoOperations operations = beanFactory.getBean(MongoOperations.class);
return RepositoryComposition.RepositoryFragments.just(new org.example.springdatamongodbfieldaot.repository.ClassAtDB2RepositoryImpl__AotRepository(operations, context));
}
});The generated code should use the bean name associated with the repository:
MongoOperations operations = beanFactory.getBean("mongoTemplateDB2", MongoOperations.class);Step to reproduces:
- ./gradlew clean build nativeTest -i
Metadata
Metadata
Assignees
Labels
theme: aotAn issue related to Ahead-Of-Time processingAn issue related to Ahead-Of-Time processingtype: bugA general bugA general bug