【发布时间】:2016-03-25 20:28:39
【问题描述】:
我有一个 Spring Boot 应用程序。
我收到以下错误
org.springframework.beans.factory.BeanCreationException: 错误 创建名为“birthdayController”的 bean:注入 autowired 依赖失败;嵌套异常是 org.springframework.beans.factory.BeanCreationException:不能 自动装配字段:私有 com.esri.birthdays.dao.BirthdayRepository com.esri.birthdays.controller.BirthdayController.repository;嵌套的 例外是 org.springframework.beans.factory.NoSuchBeanDefinitionException: 否 [com.esri.birthdays.dao.BirthdayRepository] 类型的合格 bean 找到依赖项:预计至少有 1 个符合条件的 bean 此依赖项的自动装配候选者。依赖注解: {@org.springframework.beans.factory.annotation.Autowired(required=true)} 在 org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE] 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE] 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE] 在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE] 在 org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE] 在或
以下是我的 Repository 类的代码
package com.esri.birthdays.dao;
import com.esri.birthdays.model.BirthDay;
public interface BirthdayRepository extends MongoRepository<BirthDay,String> {
public BirthDay findByFirstName(String firstName);
}
下面是控制器。
package com.esri.birthdays.controller;
@RestController
public class BirthdayController {
@Autowired
private BirthdayRepository repository;
如果它们在同一个包中就可以工作。不知道为什么
【问题讨论】:
-
你的主类在哪个包中?它的组件扫描是否涵盖存储库和控制器包?
标签: spring spring-mvc spring-boot