MongoDB autowire抛出异常

时间:2016-02-09 10:31:09

标签: java spring mongodb

我有下面的类文件,它看起来一切都很好,但我不明白为什么我得到autowire失败。有人可以帮我找到问题吗?

使用包裹详细信息更新

 package com.ui.controller;

    @RestController
    @RequestMapping(value = "/Person")
    public class PersonController {

        @Autowired
        @Lazy
        private RepoService repoService;

    }

    package com.messaging.service.impl;
    @Component
    @Lazy
    public class RepoServiceImpl implements RepoService {

        @Autowired
        @Qualifier("personRepository")
        private PersonRepository personRepo;

    }

    package com.messaging.service;
    public interface RepoService {

    }


    package com.da.repository;
    @Repository("personRepository")
    public interface PersonRepository extends MongoRepository<SomeType, String> {
    }


    package com.conf;
    @Configuration
    @EnableMongoRepositories(basePackages = "com.da.repository")
    @EnableMongoAuditing
    @Profile("mongo")
    public class MongoConfig extends AbstractMongoConfiguration {

    }

我收到以下错误:

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.da.repository.PersonRepository] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true), @org.springframework.beans.factory.annotation.Qualifier(value=personRepository)}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1301)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1047)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:942)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:533)
... 52 more

1 个答案:

答案 0 :(得分:0)

这是我的坏事。问题不在于上面的编码,而在于mongodb连接。有一个连接问题导致上述错误。