
public interface Controller {
ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse
response) throws Exception;
}
@Component("/springmvc/old-controller")
public class OldController implements Controller {
@Override
public ModelAndView handleRequest(HttpServletRequest request,
HttpServletResponse response) throws Exception {
System.out.println("OldController.handleRequest");
return null;
}
}
@Component : ์ด ์ปจํธ๋กค๋ฌ๋ /springmvc/old-controller๋ผ๋ ์ด๋ฆ์ ์คํ๋ง ๋น์ผ๋ก ๋ฑ๋ก๋์๋ค.
์ด ์ปจํธ๋กค๋ฌ๊ฐ ํธ์ถ๋๋ ค๋ฉด ๋ค์ 2๊ฐ์ง๊ฐ ํ์ํ๋ค.
HandlerMapping (ํธ๋ค๋ฌ ๋งคํ)
HandlerAdaptor (ํธ๋ค๋ฌ ์ด๋ํฐ)
์ฌ์ค์ ๊ฐ๋ฐ์๊ฐ ์ง์ ํธ๋ค๋ฌ ๋งคํ๊ณผ ํธ๋ค๋ฌ ์ด๋ํฐ๋ฅผ ๋ง๋๋ ์ผ์ ๊ฑฐ์ ์๋ค. > ์คํ๋ง์ด ์ด๋ฏธ ํ์ํ ํธ๋ค๋ฌ ๋งคํ๊ณผ ํธ๋ค๋ฌ ์ด๋ํฐ๋ฅผ ๋๋ถ๋ถ ๊ตฌํํด๋์๊ธฐ ๋๋ฌธ์ด๋ค.
HandlerMapping
| 0 = RequestMappingHandlerMapping | ์ ๋ ธํ ์ด์ ๊ธฐ๋ฐ์ ์ปจํธ๋กค๋ฌ์ธ @RequestMapping์์ ์ฌ์ฉ |
|---|---|
| 1 = BeanNameUrlHandlerMapping | ์คํ๋ง ๋น์ ์ด๋ฆ์ผ๋ก ํธ๋ค๋ฌ๋ฅผ ์ฐพ๋๋ค. |
HandlerAdapter
| 0 = RequestMappingHandlerAdapter | ์ ๋ ธํ ์ด์ ๊ธฐ๋ฐ์ ์ปจํธ๋กค๋ฌ์ธ @RequestMapping์์ ์ฌ์ฉ |
|---|---|
| 1 = HttpRequestHandlerAdapter | HttpRequestHandler ์ฒ๋ฆฌ |
| 2 = SimpleControllerHandlerAdapter | Controller ์ธํฐํ์ด์ค(์ ๋ ธํ ์ด์ X, ๊ณผ๊ฑฐ์ ์ฌ์ฉ) ์ฒ๋ฆฌ |
์ฌ๊ธฐ์ ์์๋ ์ซ์๊ฐ ์๋์ ์ผ๋ก ์์์๋ก ์ฐ์ ์์๊ฐ ๋๋ค.
- HandlerMapping์ ์์๋๋ก ์คํํด์, ํธ๋ค๋ฌ๋ฅผ ์ฐพ๋๋ค.
- ์ด ๊ฒฝ์ฐ ๋น ์ด๋ฆ์ผ๋ก ํธ๋ค๋ฌ๋ฅผ ์ฐพ์์ผ ํ๊ธฐ ๋๋ฌธ์ ์ด๋ฆ ๊ทธ๋๋ก ๋น ์ด๋ฆ์ผ๋ก ํธ๋ค๋ฌ๋ฅผ ์ฐพ์์ฃผ๋
BeanNameUrlHandlerMapping๊ฐ ์คํ์ ์ฑ๊ณตํ๊ณ ํธ๋ค๋ฌ์ธOldController๋ฅผ ๋ฐํํ๋ค.
- HandlerAdapter์ supports()๋ฅผ ์์๋๋ก ํธ์ถ
- SimpleControllerHandlerAdapter๊ฐ Controller ์ธํฐํ์ด์ค๋ฅผ ์ง์ํ๋ฏ๋ก ๋์์ด ๋๋ค.
- ๋์คํจ์ฒ ์๋ธ๋ฆฟ์ด ์กฐํํ SimpleControllerHandlerAdapter๋ฅผ ์คํํ๋ฉด์ ํธ๋ค๋ฌ ์ ๋ณด๋ ํจ๊ป ๋๊ฒจ์ค๋ค.
- SimpleControllerHandlerAdapter๋ ํธ๋ค๋ฌ์ธ OldController๋ฅผ ๋ด๋ถ์์ ์คํํ๊ณ , ๊ทธ ๊ฒฐ๊ณผ๋ฅผ ๋ฐํํ๋ค.
์ ๋ฆฌ - OldController ํธ๋ค๋ฌ ๋งคํ, ์ด๋ํฐ
- OldController๋ฅผ ์คํํ๋ฉด์ ์ฌ์ฉ๋ ๊ฐ์ฒด๋ ๋ค์๊ณผ ๊ฐ์
- HandlerMapping = BeanNameUrlHandlerMapping
- HandlerAdapter = SimpleControllerHandlerAdapter