스프링부트 war 파일로 톰캣에 배포하기

Deploy Spring Boot to Tomcat
스프링부트 톰캣에서 실행하기

1 문제상황[ | ]

  • 스프링부트 bootweb1 프로젝트를 만들었다.
  • Pivotal tc Server에 올리려고 하는데, bootweb1을 드래그해봐도 적용되지 않는다.
  • 톰캣에 앱을 올리려면 독립실행형 jar가 아니라 war 형식으로 빌드되어야 한다.

2 pom.xml 수정[ | ]

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>

	<groupId>com.example</groupId>
	<artifactId>demo</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>war</packaging>
  • Package Explorer bootweb1 [boot] 왼쪽 아이콘 아래에 빨간 엑스박스 뜸
  • 하단 Problems 탭 확인
Description	Resource	Path	Location	Type
Project configuration is not up-to-date with pom.xml. Select: Maven->Update Project... from the project context menu or use Quick Fix.	bootweb1		line 1	Maven Configuration Problem
  • 해당 행 우클릭 --- Quick Fix
  • Select a fix: Update project configuration --- [Finish]
  • 빨간 엑스박스가 사라졌다 bootweb1을 tc Server로 드래그하면 이번에는...
Server Error
Project facet Cloud Foundry Standalone Application version 1.0 is not supported.

3 프로젝트 속성 수정[ | ]

  • bootweb1 우클릭 --- Properties -- Project Facets --- Cloud Foundry Standalone Application --- [OK]
  • 이제 드래그하면 tc Server 서버 아래에 bootweb1 아이콘이 생기고 톰캣이 실행된다.
Servers 탭
bootweb1 [Started, Synchronized]
  spring-web-4.2.6.RELEASE.jar [Started, Synchronized]
  tomcat-embed-websocket-8.0.33.jar [Started, Synchronized]
Console 탭
5월 31, 2016 12:58:25 오후 org.apache.catalina.startup.Catalina load
정보: Initialization processed in 1431 ms
5월 31, 2016 12:58:27 오후 org.apache.catalina.startup.Catalina start
정보: Server startup in 1587 ms
  • 하지만...
http://localhost:8080/Pivotal tc Server 기본 페이지
http://localhost:8080/demo/Pivotal tc Server 404

4 Bootweb1Application.java 수정[ | ]

변경 전
package com.example.bootweb1;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Bootweb1Application {

	public static void main(String[] args) {
		SpringApplication.run(Bootweb1Application.class, args);
	}
}
변경 후
package com.example.bootweb1;

import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableAutoConfiguration
@ComponentScan
public class Bootweb1Application extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(Bootweb1Application.class);
    }
}
  • 다시 앱을 시작하고
5월 31, 2016 2:00:41 오후 org.apache.catalina.startup.Catalina load
정보: Initialization processed in 1503 ms

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.3.5.RELEASE)

... (생략)
2016-05-31 14:00:47.871  INFO 11012 --- [ost-startStop-1] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2016-05-31 14:00:47.889  INFO 11012 --- [ost-startStop-1] c.example.bootweb1.Bootweb1Application   : Started Bootweb1Application in 4.401 seconds (JVM running for 7.978)
2016-05-31 14:00:48.012  INFO 11012 --- [ost-startStop-1] org.apache.jasper.servlet.TldScanner     : At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
2016-05-31 14:00:48.090  INFO 11012 --- [ost-startStop-1] org.apache.jasper.servlet.TldScanner     : At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
5월 31, 2016 2:00:48 오후 org.apache.catalina.startup.Catalina start
정보: Server startup in 6370 ms
안녕 Spring Boot!
→ URL주소가 /demo 로 된 이유는 pom.xml의 artifactId를 따라 server.xml에 기재되었기 때문이다. 추후 주소 변경 가능

5 server.xml 수정[ | ]

  • Package Explorer --- Server --- Pivotal tc Server --- server.xml
<?xml version="1.0" encoding="UTF-8"?>
<Server port="${base.shutdown.port}" shutdown="SHUTDOWN">
    <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener"/>
    <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
    <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener"/>
    <Listener className="com.springsource.tcserver.serviceability.deploy.TcContainerDeployer"/>
    <Listener accessFile="${catalina.base}/conf/jmxremote.access" address="127.0.0.1" authenticate="true" className="com.springsource.tcserver.serviceability.rmi.JmxSocketListener" passwordFile="${catalina.base}/conf/jmxremote.password" port="${base.jmx.port}" useSSL="false"/>
    <GlobalNamingResources>
        <Resource auth="Container" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" name="UserDatabase" pathname="conf/tomcat-users.xml" type="org.apache.catalina.UserDatabase"/>
    </GlobalNamingResources>
    <Service name="Catalina">
        <Executor maxThreads="300" minSpareThreads="50" name="tomcatThreadPool" namePrefix="tomcat-http--"/>
        <Engine defaultHost="localhost" name="Catalina">
            <Realm className="org.apache.catalina.realm.LockOutRealm">
                <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
            </Realm>
            <Host appBase="webapps" autoDeploy="true" deployOnStartup="true" deployXML="true" name="localhost" unpackWARs="true">
                <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" pattern="%h %l %u %t &quot;%r&quot; %s %b" prefix="localhost_access_log." suffix=".txt"/>
            <!-- <Context docBase="bootweb1" path="/demo" reloadable="true" source="org.eclipse.jst.jee.server:bootweb1"/></Host> -->
            <Context docBase="bootweb1" path="" reloadable="true" source="org.eclipse.jst.jee.server:bootweb1"/></Host>
        </Engine>
        <Connector acceptCount="100" connectionTimeout="20000" executor="tomcatThreadPool" maxKeepAliveRequests="15" port="${bio.http.port}" protocol="org.apache.coyote.http11.Http11Protocol" redirectPort="${bio.https.port}"/>
    </Service>
</Server>
안녕 Spring Boot!

6 같이 보기[ | ]

7 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}