Spring Boot 개념 정리
어노테이션으로 빈등록 및 @Autowired 해주기
반오십 코린이
2023. 1. 4. 06:17
728x90
package hello.hellospring.controller;
import hello.hellospring.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
@Controller
public class MemberController {
private MemberService memberService;
@Autowired
public MemberController(MemberService memberService) {
this.memberService = memberService;
}
}
생성자로 Service를 받아와서 받아온 Service를 this 문법으로 할당해주는 모습. 이렇게 하면 Autowired 된다.
728x90