spring-boot 构建war包发布应用程序

实现步骤

修改打包方式

        在pom.xml将打包方式改成<packaging>war</packaging>html

添加Tomcat依赖

        在pom.xml中添加Tomcat的依赖坐标java

<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-tomcat</artifactId>
		</dependency>

    排除掉内置的tomcatweb

<!--Spring Boot依赖-->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>

			<!-- 排除内置容器,排除内置容器导出成war包能够让外部容器运行spring-boot项目-->
			<exclusions>
				<exclusion>
					<groupId>org.springframework.boot</groupId>
					<artifactId>spring-boot-starter-tomcat</artifactId>
				</exclusion>
			</exclusions>

		</dependency>

修改启动类

        将应用主类继承SpringBootServletInitializer 从新父类的configure方法。spring

@SpringBootApplication
public class DemoApplication extends SpringBootServletInitializer{

	public static void main(String[] args) {
		SpringApplication.run(DemoApplication.class, args);
	}

	@Override
	protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
		return builder.sources(DemoApplication.class);
//		return super.configure(builder);
	}
}

 

部署

项目部署配置

在Tomcat的webapps外的任意文件夹建立一个文件夹放war解压后的文件 例如:C:\wwwapache

最终目录以下:tomcat

在TOMCAT_HOME/conf/ server.xml 文件找到 Host 标记,在其中添加以下子标记: app

<Context path="" docBase="C:\www\admin" reloadable="false" />

 Host 标记中的 appBase 属性不要去修改,让其为默认值 "webapps"webapp

以上配置中的 Context 标记的 path 属性必定要设置为 "" 而不是 "/"ide

配置域名

假如已经申请了一个域名:www.tomcat.comspring-boot

在TOMCAT_HOME/conf/ server.xml 文件找到 Host 标记

<Host name="www.tomcat.com"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">

  			<Context path="" docBase="C:\www\admin" reloadable="false" />

            

        <!-- SingleSignOn valve, share authentication between web applications
             Documentation at: /docs/config/valve.html -->
        <!--
        <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
        -->

        <!-- Access log processes all example.
             Documentation at: /docs/config/valve.html
             Note: The pattern used is equivalent to using pattern="common" -->
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log" suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; %s %b" />

      </Host>

修改<Host name="域名">启动tomcat 访问http://www.tomcat.com:8080

访问项目须要制定端口号是8080,如今设置tomcat为80端口:

在TOMCAT_HOME/conf/ server.xml 文件找到 以下标记将8080修改成80

<Connector port="80" protocol="HTTP/1.1"
    connectionTimeout="20000"
    redirectPort="8443"
    URIEncoding="UTF-8" />

同时添加一个编码属性:URIEncoding="UTF-8"。重启tomcat 后访问:http://www.tomcat.com

相关文章
相关标签/搜索