Results 1 to 3 of 3

Thread: MongoDB RepositoryInterfaceAwareBeanPostProcessor predicting a wrong bean type

  1. #1
    Join Date
    May 2011
    Posts
    17

    Default MongoDB RepositoryInterfaceAwareBeanPostProcessor predicting a wrong bean type

    Hi

    I have two repositories

    Code:
    public interface UserRepository extends MongoRepository<User, ObjectId> {
        public User findByUsername(String username);
    }
    
    
    public interface FeedbackRepository extends MongoRepository<Feedback, ObjectId> {
        public Feedback findById(ObjectId id);
    }
    which I inject into a service class

    Code:
    @Service("myService")
    public class MyService  {
    
        @Inject
        private FeedbackRepository feedbackRepository;
    
        @Inject
        private UserRepository userRepository;
        ...
    }
    My application fails to start throwing

    "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

    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;
    	}
    In the above code predicting the bean type a cache is being maintained with beanClass as the key.
    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

  2. #2

    Default

    Have you added

    Code:
    <mongo:repositories base-package="com.your.package.repositories" mongo-template-ref="mongoTemplate" />
    and @Repository ?

  3. #3
    Join Date
    May 2011
    Posts
    17

    Default

    Hi Matthias

    Issues was related to https://jira.springsource.org/browse/DATACMNS-69

    latest snapshot build has this fix.

    Regards
    Vishnu

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •