springframework

Spring Legacy Project 서블릿 스펙 3.1로 업그레이드.

Jungsoomin :) 2020. 8. 9. 02:38

공부하던 도중, Servlet 3.x 버전대에서 는 기본적으로 업로드되는 파일을 처리할 수 있는 기능이 추가된다는 것을 보고나서 그럼 스프링 프레임워크에서의 Servlet Spec 은 어떻게 관리되며 어떻게 업그레이드 할 수 있을까. 하는 고민에 자료를 찾아보았다.

 

1. JDK -> 1.8  Perferences 의 Installed JREs 에서 JDK 추가 ( 1.8 )

 

2. 프로젝트의 <<< Compiler 설정 1.8 로 추가 -> Perferences

  1. Java Compiler 의 Enable project specific settings 체크
  2. User compliance from execution environment 'JavaSE 1.8' on the 'Java Build Path' 선택.
  3. Use default compliance settings 체크 해제 후 Compiler compliance level 을 1.8로 변경.

Servlet Spec 3.1 로 변경

 

버전만 3.1.0 으로 바꾸어 놓고 얼빠져서 왜 안되지..? 하는 경우가 있었는데, servlet-api 가 아니라 javax.servlet-api다.

<dependency>
	<groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.1.0</version>
    <scope>provided</scope>
</dependency>

 

web.xml 은 톰캣 구동 설정파일이라는 것을 기억한다. 해당 DTD 를 3.1 로 변경한다.

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

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

         xmlns="http://xmlns.jcp.org/xml/ns/javaee"

         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"

         id="WebApp_ID" version="3.1">

  <display-name>Archetype Created Web Application</display-name>

  <welcome-file-list>

    <welcome-file>index.html</welcome-file>

    <welcome-file>index.jsp</welcome-file>

  </welcome-file-list>

</web-app>

Project Facets 에서 JDK 및 Servlet 스펙 변경

프로젝트의 Preferences 에서 Project Facets 설정에서 JDK 1.8로 변경, Dynamic Web Module 3.1 로 변경.

 

불가능할 시 에는 워크스페이스 프로젝트 폴더의 .settings 폴더로 접근하여

 

org.eclipse.wst.common.project.facet.core.xml 파일 수정

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

<faceted-project>

  <fixed facet="wst.jsdt.web"/>

  <installed facet="java" version="1.8"/>

  <installed facet="jst.web" version="3.1"/>

  <installed facet="wst.jsdt.web" version="1.0"/>

</faceted-project>

 

 

이후에는 메이븐 의 pom.xml로 이동하여 메이븐 컴파일러 플러그인 설정 수정.

<plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.1</version>
        <configuration>
            <source>1.8</source>
            <target>1.8</target>
        </configuration>
    </plugin>
</plugins>

 

이후 Maven Update Project 후 확인.