prosource

두 항아리 사이의 스프링 부트 및 @ComponentScan

probook 2023. 11. 4. 10:52
반응형

두 항아리 사이의 스프링 부트 및 @ComponentScan

저는 2개의 프로젝트가 있습니다.하나는 스프링 neo4j API를 이용하여 neo4j DB에 CRUD 연산을 수행하는 DAL 프로젝트로, 이 프로젝트는 jar로 패키징되어 프로젝트 #2에 포함되어 있습니다.프로젝트 #2는 스프링 부트를 사용하여 내장된 Tomcat 서버에서 실행되는 실행 가능한 jar를 패키지화하고 만드는 Spring restful 서비스 프로젝트입니다.

Spring boot에서 생성한 실행 파일 항아리를 실행하려고 하면 이 예외가 계속 발생합니다.이 종속성에 대한 자동 배선 후보로 적합한 최소 1개의 콩이 예상됩니다.종속성 주석: {@org.springframework.콩.공장. annot.자동 연결(필수=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 답변 기준: @ComponnetScan으로 변경했습니다.

@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 프로젝트:

DAL project structure


DAL classes


DAL classes


DAL classes


DAL classes


서비스 프로젝트:

Service project structure


Service classes


Service classes


Service classes

에 대한 논쟁.@ComponentScan는 패키지 이름이고 그 문자열들은 유효한 패키지가 아닙니다.드랍 더.*Spring이 하위 패키지를 자동으로 스캔합니다.

잠시동안 이 문제가 있었습니다.@EntityScan여기에 조언된 대로 JPA와 함께하는 Spring Boot: @Entity를 다른 패키지로 이동하십시오.

도움이 되기를 바랍니다.

언급URL : https://stackoverflow.com/questions/22442822/spring-boot-and-componentscan-between-two-jars

반응형