program/spring

spring boot Jar 실행 시 Witelabel Error Page (404 Not Found) 에러 ( JSP )

yoursyun 2020. 12. 2. 13:56

JSP로 만들어진 사이트의 경우

위와 같이 build 환경을 구성하고 Excutable JAR 로 배포하면 “jsp 404 Not Found Error”에러가 발생한다.

이유는 JSP 를 지원하지 않기 때문이다. 초기 프로젝트 생성시 gradle.build 의 경우 아래와 같이 구성되어 있다.

 

plugins {

        id 'org.springframework.boot' version '2.4.0'

        id 'io.spring.dependency-management' version '1.0.10.RELEASE'

        id 'java'

}

 

group = 'com.example'

version = '0.0.1-SNAPSHOT'

sourceCompatibility = '1.8'

 

repositories {

        mavenCentral()

}

별도 설정없다면, 기본적으로 Jar 로 빌드한다. 이를 아래항목들을 추가하여 변경하면,

plugins {

        id 'war' -- add

}

 

war {

    baseName = 'demo'

    version = '0.0.1-SNAPSHOT'

}

 

War 파일로 build 할수 있다.

이때, Tomcat 서버를 이용한 배포를 위해서는 “ServletInitializer” 클래스를 구성하여 배포해야하며,

톰캣이 내장되어 있으므로, SpringBoot를 통한 직접 실행 “java –jar xxxx.war” 인 경우는 “ServletInitializer” 클래스를 만들지 않아도 된다.

 

ServletInitializer.java

import org.springframework.boot.builder.SpringApplicationBuilder;

import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;

 

public class ServletInitializer extends SpringBootServletInitializer {

@Override

    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {

        return application.sources(DemoApplication.class);

    }

}

반응형