HomeAboutMeBlogGuest
© 2025 Sejin Cha. All rights reserved.
Built with Next.js, deployed on Vercel
✍🏻
Learnary (learn - diary)
/
🌪️
Soloving_Issue_Log
/
🛫
multi-module Bean Injection Issue
🛫

multi-module Bean Injection Issue

kindOf
gradle
Created time
Jul 7, 2022 04:16 PM
Status
Done
keyword
overheadproblem내가 생각했던 문제점해결 방법
 

overhead

  • 모듈 패키지 구조
notion image
  • Gradle Tap 의존성 주입
notion image
  • 모듈 의존성
    • notion image
 

problem

🌕
module-api 프로젝트에서 module core에 있는 Entity와 Repository를 참조 하고 있다. 하지만 @SpringBootTest 즉, 통합 테스트 도중 적절한 빈을 찾지 못하였다고 한다.
  • module-api 부분에서 Member에 관한 서비스를 작성하고 참조는 잘 받았다.
    • 왜냐하면 dependcies에서 core 모듈을 의존 받았기 때문이다.
notion image
  • 하지만 실행 통합테스트 과정에서는 빨간줄이 실행됬다…
notion image
notion image
  • 해당 줄의 오류 내역
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'memberService' defined in file [/Users/yeon/IdeaProjects/moulti/module-api/out/production/classes/com/sample/api/service/MemberService.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.sample.core.repository.MemberRepository' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
 
해당 블로그를 대표적으로 여러개를 찾아보았지만, Test도 안돌리고 구성하는 방법에 관한 간단한 예시들로만 구성되어있었다.
해당 블로그는 그러한 내용이 없이 다른 모듈 잘 참조해서 가져온다…
Gradle 멀티 프로젝트 관리
Maven & Gradle 안녕하세요! 이번 시간에는 아시는 분들은 거의다 아시는(!?) Gradle을 이용한 멀티 프로젝트(모듈) 관리에 대해 소개하려고 합니다. 모든 코드는 Github 에 있으니 참고하셔서 보시면 더 좋으실 것 같습니다. 공부한 내용을 정리하는 blog-code와 세미나+책 후기를 정리하는 review, 이걸 모두 정리하는 블로그 가 있습니다.) 대부분의 서비스는 단일 프로젝트로 구성되는 일이 거의 없습니다.
Gradle 멀티 프로젝트 관리
https://jojoldu.tistory.com/123
Gradle 멀티 프로젝트 관리
Spring Boot - Intellij Gradle Multi module
이번 시간에는 Spring 프로젝트를 모듈로 변경하는 방법에 대하여 실습하겠습니다. 모듈이란 기능상 성격이 비슷하고 연관성 있는 부분들의 집합을 말합니다. 대부분의 프로그램은 작고 단순한 것에서 시작해서 크고 복잡한 것으로 점차 변화합니다. 예를 들자면 다음과 같은 경우입니다. 단순 기능 / 운영을 위한 통합 서비스( 한 프로젝트에 모든 기능을 구현) ->
Spring Boot - Intellij Gradle Multi module
https://daddyprogrammer.org/post/13156/spring-boot-change-multi-module/
Spring Boot - Intellij Gradle Multi module
 
 

내가 생각했던 문제점

  • 빈을 찾지 못하니 컴포넌트 스캔이 module-api 에서만 스캔이 일어나는 것 같으므로 componentScan 범위를 추가적으로 설정해 줘야 겠다고 생각했다. 그래서 액션 했지만…
    • notion image
    • 결과는 … 똑같다.. 왜그러는 것일까…
    • notion image
       

해결 방법

  • 그래서 있는 스캔 없는 스캔 생각해보고 넣었더니 Test가 잘된다 -끗-
    • notion image
      notion image
       

      이슈 해결 링크

      Spring Boot 멀티 모듈 프로젝트 관리
      Gradle을 이용한 멀티 모듈 프로젝트 관리 방법을 소개한다. 사용하는 이유는 프로젝트가 커질 수록 공통으로 사용하는 서버가 많아지는데 (혹은 클래스) 그 클래스들을 전부 복사&붙여넣기를 할 수 없다. 수정이 필요한 경우 전부 수정을 해야하고 실수의 여지가 많다. 하나의 공통 프로젝트를 둔 다음 해당 프로젝트에서 가져다 쓸 수 있도록 할 때 사용한다.
      Spring Boot 멀티 모듈 프로젝트 관리
      https://tweety1121.tistory.com/entry/Spring-Boot-%EB%A9%80%ED%8B%B0-%EB%AA%A8%EB%93%88-%ED%94%84%EB%A1%9C%EC%A0%9D%ED%8A%B8-%EA%B4%80%EB%A6%AC?category=959351
      Spring Boot 멀티 모듈 프로젝트 관리