복붙노트

[SPRING] 두 개의 항아리 사이의 Spring Boot 및 @ComponentScan

SPRING

두 개의 항아리 사이의 Spring Boot 및 @ComponentScan

나는 2 개의 프로젝트가있다. 하나는 spring neo4j API를 사용하여 neo4j DB에서 CRUD 작업을 수행하는 DAL 프로젝트입니다. 이 프로젝트는 병으로 포장되어 프로젝트 # 2에 포함됩니다. Project # 2 스프링 부트를 사용하여 임베디드 tomcat 서버에서 실행되는 실행 가능한 jar를 패키지화하고 작성하는 스프링 휴식 서비스 프로젝트입니다.

스프링 부트가 생성 한 실행 가능한 jar를 실행하려고 할 때 나는이 예외를 계속 발생시킵니다. 이 의존성에 대한 autowire 후보가 될 것으로 예상되는 적어도 하나의 bean. 종속성 주석 : {@ org.springframework.beans.factory.annotation.Autowired (필수 = true)}

@ComponentScan을 사용하고 있다면 독서를 기반으로 주석 디렉토리를 제공 할 수 있습니다. 따라서 내 서비스 프로젝트의 기본 디렉토리를 제공합니다. 그리고 여기에 포함 된 DAL.jar에 대한 기본 디렉토리를 제공하지만 주석이 어떻게 생겼는지는 여기에 없습니다.

의견에서 추출 :

구성 요소 검사 선언

@ComponentScan({"com.foo.dal.*","com.foo.notification.*"})

스택 트레이스 :

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'pushCommandsController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.teradata.dal.example.PushRepository com.teradata.notification.rest.controller.PushCommandsController.repository; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.teradata.dal.example.PushRepository] 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)}

최신 정보:

@chrylis 대답을 기반으로 : @ComponenetScan으로 변경

@ComponentScan({"com.teradata.notification","com.teradata.dal"})

에서 실행 중 :

java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:53)
at java.lang.Thread.run(Thread.java:744)
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'org.springframework.boot.autoconfigure.MessageSourceAutoConfiguration' is defined

DAL 프로젝트 및 서비스 프로젝트에 대한 자세한 정보 :

DAL 프로젝트 :

서비스 프로젝트 :

해결법

  1. ==============================

    1.@ComponentScan에 대한 인수는 패키지 이름이며 해당 문자열은 유효한 패키지가 아닙니다. . *를 그 (것)들에서 떨어지십시오; Spring은 서브 패키지를 자동으로 검사합니다.

    @ComponentScan에 대한 인수는 패키지 이름이며 해당 문자열은 유효한 패키지가 아닙니다. . *를 그 (것)들에서 떨어지십시오; Spring은 서브 패키지를 자동으로 검사합니다.

  2. ==============================

    2.잠시 동안이 똑같은 문제가 있었으면, @EntityScan이 나에게 트릭을 했어. JPA로 스프링 부트 : @Entity를 다른 패키지로 옮긴다.

    잠시 동안이 똑같은 문제가 있었으면, @EntityScan이 나에게 트릭을 했어. JPA로 스프링 부트 : @Entity를 다른 패키지로 옮긴다.

    희망은 도움이 Logged

  3. from https://stackoverflow.com/questions/22442822/spring-boot-and-componentscan-between-two-jars by cc-by-sa and MIT license