학습 목표
- Spring Legacy Project 를 만들 수 있다
@Service 로 Bean 등록 + @Autowired 로 주입까지 한 흐름
- Part 2 의 모든 학습이 한 화면으로 모인다
1. 프로젝트 생성 5 단계
- File → New → Spring Legacy Project
- Spring MVC Project 템플릿
- 패키지명 점 3 개 이상 (예: com.example.demo)
- Maven Update Project
- 의존성 다운로드 대기
2. 핵심 코드 한눈에
@Service
public class HelloService {
public String getMessage() {
return "Spring Bean 으로 인사드립니다!";
}
}
@Controller
public class HomeController {
@Autowired
private HelloService helloService; ← 자동 주입
@RequestMapping("/")
public String home(Model model) {
model.addAttribute("msg", helloService.getMessage());
return "home";
}
}
3. 일어난 일
브라우저 GET /
→ DispatcherServlet
→ HomeController.home()
→ HelloService.getMessage() (Bean 자동 주입 결과)
→ model 에 담기
→ "home" → home.jsp
→ ${msg} 채워서 응답
4. ⚠️ 실험으로 확인
@Service 를 빼보면: "No qualifying bean of type 'HelloService'" 에러. Bean 등록 없이는 자동 주입이 불가능함을 직접 체험.
5. Before / After
Part 2 끝
Spring 컨테이너가 두 Bean 을 자동 연결해 응답을 만든다
학습 확인 체크리스트
- Spring Legacy Project 생성 절차를 안다
@Service + @Autowired 의 협업을 코드로 본다
- Maven Update 함정을 피한다
- Bean 미등록 시 에러 메시지를 안다