inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

스프링 입문 - 코드로 배우는 스프링 부트, 웹 MVC, DB 접근 기술

컴포넌트 스캔과 자동 의존관계 설정

DI 와 전반적인 구조 질문

353

손 훈서

작성한 질문수 1

0

[질문 템플릿]
1. 강의 내용과 관련된 질문인가요? (예/아니오) 네
2. 인프런의 질문 게시판과 자주 하는 질문에 없는 내용인가요? (예/아니오) 네
3. 질문 잘하기 메뉴얼을 읽어보셨나요? (예/아니오) 네

[질문 내용]
1. 회원 서비스를 테스트할 때, DI를 하는 이유를 저는 아래처럼 이해했는데 이것이 맞는 이해인지 궁금합니다.

  1. 위 내용이 맞다면, 모듈 테스트를 하지 않는다는 가정하에 해당 부분 뒤에 나오는 스프링 통합 테스트를 할 때는 이미 스프링 컨테이너에 레포지토리가 등록되어 있으므로 생성자를 활용한 의존성 주입이 필요없는 것이 맞나요?

 

  1. 아래 그림은 최종적으로 제가 구조를 이해한 것을 구조화 한 것인데 혹시 틀린 부분이 있는지 궁금합니다.

java spring mvc spring-boot

답변 1

0

인프런 AI 인턴

안녕하세요, 인프런 AI 인턴입니다.

  1. 네, 귀하의 이해는 맞습니다. 의존성 주입(DI)을 통해 MemberServiceMemoryMemberRepository가 동일한 인스턴스를 참조하도록 하여 일관성 있는 데이터 활용이 가능해지며, 또한 이는 테스트 용이성을 향상시킵니다.

  2. 스프링 통합 테스트에서는 스프링 컨테이너를 사용하여 의존성을 관리합니다. 즉, 스프링 컨테이너가 자동으로 의존성을 주입해주기 때문에 개발자가 직접 생성자를 통해 의존성을 주입할 필요가 없습니다. 그러므로 여러분의 이해는 옳습니다.

  3. 제공해주신 다이어그램은 스프링 프레임워크 응용 프로그램의 전형적인 구조를 잘 나타내고 있습니다. 도메인, 서비스, 리포지토리 및 컨트롤러 간의 관계와 스프링 컨테이너에 의한 의존성 주입 방식을 정확하게 설명하고 있습니다. @Autowired를 사용한 의존성 주입과 각 계층(Controller, Service, Repository)의 역할도 적절히 표현되어 있습니다. 특별히 지적할 오류는 보이지 않습니다.

This image appears to be a diagram representing the structure of a Spring Framework application in the context of Java development. The diagram is labeled in Korean and depicts different components of a typical Spring application and how they are interconnected. Here’s an explanation of the elements in the diagram:1. 스프링 컨테이너 (IoC Container): This translates to “Spring Container (IoC Container),” which is referring to the Inversion of Control container provided by the Spring Framework that manages the lifecycle and configuration of the application beans.2. 컨트롤러 (Controller): Refers to the Controller component in a Spring MVC (Model-View-Controller) application. It’s annotated with `@Controller`, indicating that it’s a Spring MVC controller.3. 서비스 (Service): Stands for the Service layer, which contains business logic. It’s annotated with `@Service` or could be defined in a configuration with `@Bean`.4. 리포지토리 (Repository): This is the Repository layer, responsible for data access operations, and is annotated with `@Repository` or again, alternatively defined in a configuration with `@Bean`.The `@Autowired` annotations indicate where Spring should perform dependency injection, automatically wiring beans together.5. 도메인 (Domain): Represents the Domain layer, which includes entities and domain logic in the application.6. DB: Represents the database with which the application interacts.The rectangles (domain, service, repository) seem to correspond to the layers of the application, while the arrows represent the flow of control or dependencies.Please note that the explanations are also annotated with terms like `데이터`, `Jdbc`, `JPA 등`, which refer to data, JDBC (Java Database Connectivity), JPA (Java Persistence API), indicating technologies that might be used in the repository layer for data access in the database.This diagram provides an overview of beans and their relationships often used in object-oriented programming with the Spring framework, focusing on the use of annotations (`@Controller`, `@Service`, `@Repository`, `@Autowired`) to declare components and manage dependency injection.

..

0

74

2

Unused property.....

0

98

2

project JDK is misconfigured

0

129

2

외부 API의 ID 타입(String/UUID)과 내부 도메인의 ID 타입(Long)이 불일치할 때의 설계 정석

0

82

2

단위/통합 테스트 버전충돌 문제

0

91

2

❗️springboot 4.0.2 버전 aspectj dependency 설정❗️

0

227

1

왜 컨트롤러는 변한게 없는데 새로 만든 html 파일이 뜨나요?

0

101

2

윈도우 build test오류 질문

1

102

2

테스트 관련 공부에 대한 조언을 얻고 싶습니다

0

98

2

테스트 실행 시 에러 질문

0

289

1

name을 통한 비교와 객체를 통한 비교

0

77

1

빌드 후 libs 없음

1

128

1

윈도우 gradlew.bat 에러

0

167

1

@PostMapping("/members/new")가 동작하지 않습니다

0

88

1

java static class와 kotlin class

0

77

1

스프링 DB연결

0

126

1

소요 시간

0

85

2

ddl.sql에 빨간 밑줄

1

101

2

welcome page 에러

0

180

3

잘 모르겠습니다.

0

163

2

fail을 똑같이 쳤는데 오류가 발생해요

0

156

2

index.html Welcome page

0

120

1

프로젝트 gradle-groovy ?

0

364

1

테스트코드 메서드명 한글

0

198

2