Spring Quick Start(์ฑ )์ Day4 class03 ์ ๊ณต๋ถํ ๋ด์ฉ์ ๋๋ค.
๊ฐ์ธ์ ์ผ๋ก ์์ฃผ ์ค์ํ ๋ถ๋ถ์ด๋ผ๊ณ ์๊ฐํฉ๋๋ค!
<web-app>
<filter>
<filter-name>characterEncoding</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>EUC-KR</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>characterEncoding</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- <servlet-name>์ ๋ด dispatcher-servlet.xml์ด "๋ทฐ" ์ค์ ํ์ผ -->
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:dispatcher-servlet.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
</web-app>
โ ์๋ฒ๋ฅผ ์ฒ์์ผ๋ก ๊ตฌ๋ํ๋ฉด web.xml ํ์ผ์ ๋ก๋ฉํ์ฌ ์๋ธ๋ฆฟ ์ปจํ ์ด๋๊ฐ ๊ตฌ๋๋๋ค.
โก ์๋ธ๋ฆฟ ์ปจํ ์ด๋๋ web.xml ๋ฑ๋ก๋ ContextLoaderListener ๊ฐ์ฒด๋ฅผ ์์ฑ(pre loading)ํ๋ค. ์ด๋ ContextLoaderListener ๊ฐ์ฒด๋ src/main/resources ํด๋์ ์๋ applicationContext.xml ํ์ผ์ ๋ก๋ฉํ์ฌ ์คํ๋ง ์ปจํ ์ด๋๋ฅผ ๊ตฌ๋ํ๋๋ฐ, ์ด๋ฅผ 'Root ์ปจํ ์ด๋'๋ผ๊ณ ํ๋ค. ์ด๋ ServiceImpl ํด๋์ค(@Service)๋ DAO ๊ฐ์ฒด(@Repository)๋ค์ด ๋ฉ๋ชจ๋ฆฌ์ ์์ฑ๋๋ค.
์ฌ๊ธฐ์ ์ ๊น, ์ ์์๊ฐ ์ด๋ ๊ฒ ๋ ๊น?
์ปจํธ๋กค๋ฌ๊ฐ ์์ฑ๋๋ ๊ณผ์ ์์ @Autowired๋ก ์์กด์ฑ ์ฃผ์ ์ ์ฒ๋ฆฌํ๋ ค๊ณ ํ๋๋ฐ ๊ทธ ๋น๋ค์ด ์์ผ๋ฉด ์๋๊ฒ ์ง?
๋น์ฆ๋์ค ์ปดํฌ๋ํธ๋ค ์ฆ ์์กด์ฑ ์ฃผ์ ์ด ๋๋ ๊ฐ์ฒด๊ฐ ๋ฐ๋์ ๋ฉ๋ชจ๋ฆฌ์ ๋จผ์ ์ฌ๋ผ๊ฐ ์์ด์ผ ์ปจํธ๋กค๋ฌ ๋น์ด ์์ฑ๋ ์ ์์ด
โข ์ฌ์ฉ์๊ฐ ๋ก๊ทธ์ธ ๋ฒํผ์ ํด๋ฆญํ์ฌ ".do" ์์ฒญ์ ์๋ฒ์ ์ ๋ฌํ๋ฉด web.xml์ ๋ฑ๋ก๋ ๋๋ก ์๋ธ๋ฆฟ ์ปจํ ์ด๋๋ DispatcherServlet ๊ฐ์ฒด๋ฅผ ์์ฑํ๊ณ /WEB-INF/config ํด๋์ ์๋ presentation-layer.xml ํ์ผ ๋๋ dispatcher-servlet.xml ํ์ผ์ ๋ก๋ฉํ์ฌ ๋๋ฒ์งธ ์คํ๋ง ์ปจํ ์ด๋๋ฅผ ๊ตฌ๋ํ๋ค. ์ด ๋ ๋ฒ์งธ ์คํ๋ง ์ปจํ ์ด๋๊ฐ Controller ๊ฐ์ฒด(@Controller)๋ฅผ ๋ฉ๋ชจ๋ฆฌ์ ์์ฑํ๋ค. ์ด๋ ์์์ Root ์ปจํ ์ด๋(๋ถ๋ชจ ์ปจํ ์ด๋)๊ฐ ์์ฑํ ๊ฐ์ฒด๋ฅผ Controller์์ ์ฐธ์กฐํด์ ์ฌ์ฉํ๋ค. ์๋ ๊ทธ๋ฆผ์ด ์ด์ ๊ด๋ จ๋ ๊ทธ๋ฆผ์ด๋ค.
๋ถ๋ช ํ ์คํ๋ง ์ปจํ ์ด๋๋ ๋ ๊ฐ๊ฐ ๊ตฌ๋๋๋ค.
ContextLoaderListener์ DispatcherServlet์ด XmlWebApplicationContext๋ฅผ ์์ฑํ๋๋ฐ ๋ ์คํ๋ง ์ปจํ ์ด๋์ ์ญํ ๊ณผ ๊ฐ๋ฅ์ด ๋ค๋ฅธ ๊ฒ์ด๋ค.
'Spring > Spring Quick Start' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
JPA ํ๋ก์ ํธ (0) | 2021.01.08 |
---|---|
Mybatis ํ๋ก์ ํธ (0) | 2021.01.08 |
์๋ธ๋ฆฟ ๊ฐ์ฒด์ service() ๋ฉ์๋๊ฐ ํธ์ถ๋๋ ๊ณผ์ (0) | 2021.01.07 |
intelliJ ํฐ์บฃ ์๋ฒ๋ก ์คํํ๊ธฐ (0) | 2021.01.07 |
IntelliJ๋ก, Spring ํ๋ก์ ํธ(maven) ์์ฑํ๊ธฐ (0) | 2021.01.07 |
IntelliJ Add Framework Support์ Spring์ด ๋ณด์ด์ง ์์ ๋ (0) | 2021.01.07 |