Hi
I have two repositories
which I inject into a service classCode:public interface UserRepository extends MongoRepository<User, ObjectId> { public User findByUsername(String username); } public interface FeedbackRepository extends MongoRepository<Feedback, ObjectId> { public Feedback findById(ObjectId id); }
My application fails to start throwingCode:@Service("myService") public class MyService { @Inject private FeedbackRepository feedbackRepository; @Inject private UserRepository userRepository; ... }
"Caused by: org.springframework.beans.factory.NoSuchBeanDefini tionException: No matching bean of type [com.space.repository.mongo.FeedbackRepository]"
When I debugged further I noticed RepositoryInterfaceAwareBeanPostProcessor.predictB eanType() returning a cached bean type of UserRepository for FeedbackRepository
In the above code predicting the bean type a cache is being maintained with beanClass as the key.Code:public Class<?> predictBeanType(Class<?> beanClass, String beanName) { if (null == context || !REPOSITORY_TYPE.isAssignableFrom(beanClass)) { return null; } BeanDefinition definition = context.getBeanDefinition(beanName); PropertyValue value = definition.getPropertyValues().getPropertyValue( "repositoryInterface"); if (cache.containsKey(beanClass)) { return cache.get(beanClass); } Class<?> resolvedBeanClass = getClassForPropertyValue(value); cache.put(beanClass, resolvedBeanClass); return resolvedBeanClass; }
For all repository instances "MongoRepositoryFactoryBean" is the bean class and hence for feedbackRepository bean predictBeanType is picking up a cached userRepository as the type.
Looks like a bug ?
Note: I am hitting this bug when a latest snapshot was downloaded by maven build - spring-data-commons-core-1.2.0.BUILD-20110901.083156-54
This issues was not there in older builds (may be 2/3 days back).
Regards
Vishnu


Reply With Quote