2017-02-26

1. 개발 환경 설정(1)

* maven 없이 spring 사용하기

1. 새로운 프로젝트 생성
   New - Dynamic Web Project 


* 만들어야 하는 폴더 구조















  

2. WEB-INF 내의 lib 폴더에 라이브러리 추가 
    1) springframework( 사용하려는 버전에 맞춰서)
    2) jstl 
    3) commons-logging


3. 설정 파일 생성
    1) WEB-INF 내에 web.xml 생성 


<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns="http://java.sun.com/xml/ns/javaee"
           xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
           version="3.0">

   <display-name> SpringTest</display-name>

   <context-param>
       <param-name>contextConfigLocation</param-name>
       <param-value>
          /WEB-INF/spring/root-context.xml
          <!-- /WEB-INF/spring/appServlet/dao-context.xml-->
          <!--/WEB-INF/spring/appServlet/service-context.xml -->
       </param-value>
   </context-param>

   <listener>
       <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
   </listener>

   <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</param-value>
       </init-param>
       <load-on-startup>1</load-on-startup>
   </servlet>


   <servlet-mapping>
      <servlet-name>appServlet</servlet-name>
      <url-pattern>/</url-pattern>
   </servlet-mapping>

   <welcome-file-list>
      <welcome-file>/WEB-INF/index.jsp</welcome-file>
   </welcome-file-list>


   <filter>
      <filter-name>encodingFilter</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>

     <init-param>
         <param-name>forceEncoding</param-name>
         <param-value>true</param-value>
     </init-param>

   </filter>

   <filter-mapping>
     <filter-name>encodingFilter</filter-name>
     <url-pattern>/*</url-pattern>
   </filter-mapping>

</web-app>

  2) root-context.xml


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

  <mvc:annotation-driven />

</beans>




  3) servlet-context.xml



<?xml version="1.0" encoding="UTF-8"

<beans xmlns="http://www.springframework.org/schema/beans"  
xmlns:mvc="http://www.springframework.org/schema/mvc"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    
  xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
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/context/spring-context.xsd">
  
  <mvc:annotation-driven />

<!--  <mvc:resources mapping="/resources/**" location="/resources/" />-->

<!--  <bean id="annotationMapper" class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
<property name="order" value="0" /> 
</bean> 
-->

<bean id="viewResolver"  class="org.springframework.web.servlet.view.UrlBasedViewResolver">  
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/view/" />  
<property name="suffix" value=".jsp" />  
</bean>  

<context:component-scan base-package="com.test.controller" />

</beans>