springboot项目打成war包部署在tomcat

1、新建springboot项目

springboot项目打成war包部署在tomcat_第1张图片
image.png

2、pom.xml



    4.0.0
    
        org.springframework.boot
        spring-boot-starter-parent
        2.1.8.RELEASE
         
    
    com.test
    hello
    0.0.1-SNAPSHOT
    hello
    war
    Demo project for Spring Boot

    
        1.8
    

    
        
            org.springframework.boot
            spring-boot-starter-web
        

        
            org.springframework.boot
            spring-boot-starter-test
            test
        
    

    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
            
        
    

3、Hello.java控制类

package com.test.hello;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping
@RestController
public class Hello {

    @GetMapping("/hello")
    public String hello(){
        return "hello wzf";
    }
}

4、HelloApplication.java主类

package com.test.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 HelloApplication extends SpringBootServletInitializer{

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(HelloApplication.class);
    }

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

}
springboot项目打成war包部署在tomcat_第2张图片
image.png

5、打包war

springboot项目打成war包部署在tomcat_第3张图片
image.png

6、war包修改名称后放在外部tomcat的webapps目录下,启动tomcat,war包会自动解压

springboot项目打成war包部署在tomcat_第4张图片
image.png

7、访问

springboot项目打成war包部署在tomcat_第5张图片
image.png

你可能感兴趣的:(springboot项目打成war包部署在tomcat)