지난 글에서 회원 서비스와 회원 리포지토리의 @Service, @Repository, @AutoWired 어노테이션을 제거하고 진행한다. 컨트롤러는 그대로 둔다.
service 패키지 아래 ServiceConfig 파일을 생성하여 다음과 같이 작성한다.
package hello.hellospring.service;
import hello.hellospring.repository.MemberRepository;
import hello.hellospring.repository.MemoryMemberRepository;
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();
}
}