A FactoryBean<T> using a package private target type T leads to compile errors in the generated code when the FactoryBean implementation is not in the same package.
Given a package private repository CustomerRepository is located in com.example.data.mongo, and a factory BeanDefinition using MongoRepositoryFactoryBean<CustomerRepository, Object, Object> as target results in the following code being generated in the org.springframework.data.mongodb.repository.support package, where the MongoRepositoryFactoryBean is located.
package org.springframework.data.mongodb.repository.support;
/**
* Bean definitions for {@link MongoRepositoryFactoryBean}
*/
public class MongoRepositoryFactoryBean__BeanDefinitions {
/**
* Get the bean definition for 'customerRepository'
*/
public static BeanDefinition getCustomerRepositoryBeanDefinition() {
ResolvableType beanType = ResolvableType.forClassWithGenerics(MongoRepositoryFactoryBean.class, CustomerRepository.class, Object.class, Object.class);
RootBeanDefinition beanDefinition = new RootBeanDefinition(beanType);
beanDefinition.setLazyInit(false);
beanDefinition.getConstructorArgumentValues().addIndexedArgumentValue(0, "com.example.data.mongo.CustomerRepository");
beanDefinition.getPropertyValues().addPropertyValue("queryLookupStrategyKey", QueryLookupStrategy.Key.CREATE_IF_NOT_FOUND);
beanDefinition.getPropertyValues().addPropertyValue("lazyInit", false);
beanDefinition.getPropertyValues().addPropertyValue("namedQueries", new RuntimeBeanReference("mongo.named-queries#0"));
beanDefinition.getPropertyValues().addPropertyValue("repositoryFragments", new RuntimeBeanReference("mongodb.CustomerRepository.fragments#0"));
beanDefinition.getPropertyValues().addPropertyValue("mongoOperations", new RuntimeBeanReference("mongoTemplate"));
beanDefinition.getPropertyValues().addPropertyValue("createIndexesForQueryMethods", false);
beanDefinition.setAttribute("factoryBeanObjectType", "com.example.data.mongo.CustomerRepository");
beanDefinition.setInstanceSupplier(InstanceSupplier.of(MongoRepositoryFactoryBean__BeanDefinitions::getCustomerRepositoryInstance));
return beanDefinition;
}
Visibility checks should consider the generic arguments and potentially guard/load those via reflection.
A
FactoryBean<T>using a package private target typeTleads to compile errors in the generated code when theFactoryBeanimplementation is not in the same package.Given a package private repository
CustomerRepositoryis located incom.example.data.mongo, and a factoryBeanDefinitionusingMongoRepositoryFactoryBean<CustomerRepository, Object, Object>as target results in the following code being generated in theorg.springframework.data.mongodb.repository.supportpackage, where theMongoRepositoryFactoryBeanis located.Visibility checks should consider the generic arguments and potentially guard/load those via reflection.