본문 바로가기

dependency injection3

[Spring Bean과 의존관계 - (2)] Java Code 로 직접 Spring Bean 에 등록하기 기존에 Component Scan 방식이 아닌 직접 자바 코드를 이용해서 Bean 에 등록할 것이기 때문에, Controller를 제외한 @Service, @Repository, @Autowired 를 제거한다. SpringConfig Main method Scope 에 SpringConfig class 를 생성하고, 다음과 같이 작성한다. Spring 이 @Configuration 으로 인식하면, @Bean annotation으로 등록한 MemberService 와 MemberRepository 를 Bean 으로 등록한다. MemberService 에서 MemberRepository 가 Bean 으로 등록되어 있는지 Spring container 내에서 객체를 찾고, 위에서 @Bean 으로 등록했기 때.. 2022. 7. 1.
[Spring Bean과 의존관계 - (1)] Component Scan 과 자동 의존관계 설정 간단히말해, 기존에 작성한 Service 와 Repository, Controller 를 @Service, @Repository, @Controller 어노테이션을 이용하여 Spring Container 가 자동으로 Bean 에 등록하고, 의존관계를 설정할 수 있도록 한다. Spring Bean 을 등록하는 방법에는 두 가지가 있다. Component Scan 으로 자동 의존관계 설정 - @Component : @Controller, @Service, @Repository 자바 코드로 직접 Spring Bean 에 등록 이번에 알아볼 방법은 1번이다. controller > MemberController 생성 **@Controller 를 설정했을 때 벌어지는 일 한마디로 Spring container에서.. 2022. 7. 1.
[회원 관리 예제, 백엔드 개발 - (5)] 회원 서비스 테스트 git repository : https://github.com/Rezalog/spring-boot-entry-inf GitHub - Rezalog/spring-boot-entry-inf Contribute to Rezalog/spring-boot-entry-inf development by creating an account on GitHub. github.com 구현한 회원 서비스, MemberService 를 테스트하기 위한 코드를 작성해보자. 이때 테스트 코드 작성시, given-when-then 으로 나누어 작성하는 습관을 들이자! (**cmd + shift + T 로 테스트 자동 생성이 가능 !) MemberServiceTest beforeEach MemoryMemberRepository 은 .. 2022. 6. 30.