无法自动接线[错误:没有匹配的bean类型]

时间:2019-07-19 07:40:07

标签: java spring hibernate jpa

我试图部署我的项目,但出现此错误,但未能解决。

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'educationUserDetailsBuilder': Injection of autowired dependencies failed; nested exception is
org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.metaarchit.education.school.persistence.SemesterDao com.metaarchit.education.framework.security.spring.EducationUserDetailsBuilder.semesterDao; nested exception is 
org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.metaarchit.education.school.persistence.SemesterDao] 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)}
    at 
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:285)

我不知道该贴什么,如果您需要其他可以提供帮助的内容,请告诉我您需要什么文件。

1 个答案:

答案 0 :(得分:0)

您在某处有SemesterDao类,对吗?您可能在代码中做了类似的事情:

public class MyClass {
@Autowire
private SemesterDao semesterDao;
...

这只有在Spring知道如何创建实例的情况下才能正常工作。您可以通过进入课程并在其上添加一个名为Component的注释来实现此目的:

@Component
public class SemesterDao {
}

出于好奇,当同时使用Spring和Spring Data时,这种方式可以扩展JpaRepository并且已经实现了许多有用的方法。您可以在这里进一步查看:https://www.baeldung.com/the-persistence-layer-with-spring-data-jpa