springboot打war包部署到tomcat
1:build.gradle
plugins { id 'org.springframework.boot' version '2.1.5.RELEASE' id 'java' } apply plugin: 'io.spring.dependency-management' group = 'com.example' version = '0.0.1-SNAPSHOT' sourceCompatibility = '1.8' apply plugin: 'war' repositories { mavenCentral() } dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' testImplementation 'org.springframework.boot:spring-boot-starter-test' compile group: 'com.google.code.gson', name: 'gson', version: '2.8.2' providedRuntime('org.springframework.boot:spring-boot-starter-tomcat') }
增加:
apply plugin: 'war'
providedRuntime('org.springframework.boot:spring-boot-starter-tomcat')
2:application.properties中增加
spring.jmx.enabled=false
3:入口程序继承SpringBootServletInitializer,覆写configure方法
package com.example.demo; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; @SpringBootApplication public class DemoApplication extends SpringBootServletInitializer { @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(DemoApplication.class); } public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); } }