제 질문은 스프링 부트를 사용하지 않기 때문에 제 질문과 거의 동일합니다. . Can't Autowire @Repository annotated interface in Spring Boot 저는 할 수 없습니다 @EnableJpaRepositories
제 경우에는 스프링 부트 러너가 없습니다. SpringMVC 컨트롤러는 웹 앱 안에 있습니다.스프링 데이터 : @Repository JpaRepository 인터페이스를 Autowire 할 수 없습니다. "autowire 후보로 인정되는 적어도 하나의 bean"
일반 구식 SpringMVC 응용 프로그램에서 Spring 데이터를 독립적으로 사용하고 있습니다.
내가 봄 데이터에 대한
DAO 인터페이스, @Repository주의 오류
Caused by: No qualifying bean of type 'com.myapp.dao.QuestionsDAO' available:
expected at least 1 bean which qualifies as autowire candidate.
받고 있어요 :
@Repository
public interface QuestionsDAO extends JpaRepository<Question, Long> {
public String findById(Long id);
}
서비스는 다음이 DAO를 사용해야를 autowire가 :
구성 요소
public class SchedulingService {
@Autowired
QuestionsDAO questionsDAO;
public String findLabelById(Long id) {
return questionsDAO.findById(id);
}
}
구성 요소 검색이 활성화되어 있으며 다른 모든 경우에 사용할 수 있습니다.
<context:component-scan base-package="com.myapp" />
스프링 데이터는 스프링 부트에서만 허용됩니까?
하지만 스프링 어노테이션이 필요합니까? 그렇지 않으면 Autowire가 작동하지 않습니까? 저장소 인터페이스에 @Component를 제안 하시겠습니까? –
아니요,'@ EnableJpaRepositories' 또는''가 처리합니다. 구성된 패키지를 검사하고 Spring 데이터 인터페이스 중 하나를 확장하는 모든 인터페이스를 확인합니다. 따라서 인터페이스 자체에 대한 주석이 필요하지 않습니다. –
dunni