Spring Framework

스프링 이야기 2. controller 만들기

김푸른초푸른 2020. 2. 22. 17:33

1. 어노테이션으로 controller 만들기 

 

1) bean에 일일이 등록할 필요가 없다! 

2) @controller을 쓸 클래스 위에 적으면 설정파일에 context : component - scan으로 컨테이너가 컨트롤러 객체를 자동으로 생성

3) controller 상속이 필요없이 어노테이션만 있으면 된다! 

4) <context:component-scan base-package="controller"> 이 servlet.xml에 등록되어 있어야한다

-> 스스로 만든 것으로 new -> spring bean configuration file에서 생성

 

5) 어노테이션 등록시에 생성한 servlet.xml에 등록하기

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:context="http://www.springframework.org/schema/beans"
 xsi:schemaLocation="http://www.springframework.org/schema/beans
 http://www.springframework.org/schema/beans/spring-beans.xsd
 http://www.springframework.org/schema/context
 http://www.springframework.org/schema/spring-contexrt-4.2.xsd">

 

 <context:component-scan base-package="com.springbook.view">
 </context:component-scan>

 

 

 

 

참고 :https://okky.kr/articles/478569