1. ProjectExplorer 우클릭 -> [NEW] -> [Spring Legacy Project]
2. [Next] 눌러서 Package을 설정한다.
3. pom.xml
JDK 버전과 Spring 의 버전을 사용하는 버전과 맞춰준다.
<properties>
<java-version>1.8</java-version>
<org.springframework-version>5.0.6.RELEASE</org.springframework-version>
<org.aspectj-version>1.6.10</org.aspectj-version>
<org.slf4j-version>1.6.6</org.slf4j-version>
</properties>
4. Project Explorer 에서 우클릭 -> [Properties] -> [Project facets] java 버전 맞춰준다.
5. web.xml 파일에서 DispatcherServlet을 설정하고 init-param 속성으로 DispatcherServlet 관련된 설정을
등록한다.
6. web.xml 파일에 어플리케이션 컨텍스트를 설정한다.
*.do 로 들어오는 클라이언트의 요청을 DispatcherServlet이 처리하도록 설정
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee https://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>characterEncoding</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>characterEncoding</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>
<!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/root-context.xml</param-value>
</context-param>
<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Processes application requests -->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml
classpath:applicationContext.xml
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
</web-app>
7. DispatcherServlet이 스프링 컨테이너에서 어노테이션으로 표기한 객체들을 검색 할 수 있도록
스프링 설정파일(WEB-INF/spring/appServlet/servlet-context.xml)에 <annotation-driven/> 등록한다.
8. DispatcherServlet이 스프링 컨테이너에서 컨트롤러를 객체를 검색할 수 있도록 스프링 설정파일에
컨트롤러 빈을 등록한다.
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">
<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->
<!-- Enables the Spring MVC @Controller programming model -->
<!-- Spring MVC @Controller를 통한 의존성 주입!!!! -->
<annotation-driven />
<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/" />
<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
<!-- ViewResolver 가 "/view/뷰이름/.jsp" 형식의 뷰 JSP를 사용하도록 설정한다! -->
</beans:bean>
<beans:bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<beans:property name="maxUploadSize" value="10485760"/>
</beans:bean>
<context:component-scan base-package="org.kh.member" />
<context:component-scan base-package="org.kh.board" />
</beans:beans>
'이공계전문기술연수 > Spring Framework' 카테고리의 다른 글
<이공계기술전문연수> Spring MVC(View 흐름) (0) | 2019.11.26 |
---|---|
<이공계기술전문연수> Spring과 외부 라이브러리 연결 (0) | 2019.11.26 |
<이공계기술전문연수> 1. Framework 특징 (0) | 2019.11.19 |
<이공계기술전문연수> Spring MVC (0) | 2019.11.11 |
<이공계기술전문연수> Spring 결합도 / beanTest / 어노테이션 (0) | 2019.11.11 |