将spring boot部署到tomcat上

阅读更多
1.将项目的启动类Application.java继承SpringBootServletInitializer并重写configure方法
package hello;

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 Application {

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

}*/

@SpringBootApplication
public class Application extends SpringBootServletInitializer {
 
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(Application.class);
    }
 
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

2.pom.xml配置如下

  4.0.0
  info.frady
  springmvc
  war
  0.0.1-SNAPSHOT
  springmvc Maven Webapp
  http://maven.apache.org
   
        org.springframework.boot
        spring-boot-starter-parent
        2.0.3.RELEASE
    

    
        
            org.springframework.boot
            spring-boot-starter-web
        
        
            org.springframework.boot
            spring-boot-starter-thymeleaf
        
        
            org.springframework.boot
            spring-boot-devtools
            true
        
    

    
        1.8
    
  
  
    springmvc
  
  
  


3.在项目根目录,执行 mvn clean package ,将项目打包为war包
4.将war包文件复制到你所安装的tomcat目录中webapps目录中,tomcat会自动加载,不需要重启
完成,以上操作在tomcat9.0.11、java1.8.0.172、maven3.5.0验证通过
代码参照
https://spring.io/guides/gs/rest-service/
https://spring.io/guides/gs/spring-boot/
https://spring.io/guides/gs/serving-web-content/#use-maven

你可能感兴趣的:(将spring boot部署到tomcat上)