앞선 실습에서 붙인 @Service와 @Repository를 삭제하고 자바 코드로 스프링 빈을 등록한다.
service 아래에 ServiceConfig 클래스 생성
*ServiceConfig
package hello.hello_spring.service;
import hello.hello_spring.repository.MemberRepository;
import hello.hello_spring.repository.MemoryMemberRepository;
import hello.hello_spring.service.MemberService;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class SpringConfig {
@Bean
public MemberService memberService() {
return new MemberService(memberRepository());
}
@Bean
public MemberRepository memberRepository() {
return new MemoryMemberRepository();
}
}
김영한 강사님의 '스프링 입문 - 코드로 배우는 스프링 부트, 웹 MVC, DB 접근 기술'을 듣고 정리한 것입니다.
'Spring Boot' 카테고리의 다른 글
[스프링 입문] 용어 정리 (0) | 2024.07.11 |
---|---|
[스프링 입문] 회원 웹 기능 - 홈 화면 추가, 등록, 조회 (0) | 2024.06.27 |
[스프링 입문] 컴포넌트 스캔과 자동 의존관계 설정 (0) | 2024.06.27 |
[스프링 입문] 회원 서비스 개발, 테스트 (0) | 2024.06.27 |
[스프링 입문] 회원 리포지토리 테스트 케이스 작성 (0) | 2024.06.27 |