SpringBoot2中怎么构建可部署的war包-成都快上网建站

SpringBoot2中怎么构建可部署的war包

SpringBoot2中怎么构建可部署的war包,针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。

成都地区优秀IDC服务器托管提供商(创新互联建站).为客户提供专业的资阳主机托管,四川各地服务器托管,资阳主机托管、多线服务器托管.托管咨询专线:13518219792

1、新建一个名称为demo的Spring Boot项目。

2、修改pom.xml文件

下面粗体部分为所加代码,注释掉原来的build节点,该项目最终会打包成一个war-demo的war包。

 4.0.0      org.springframework.boot    spring-boot-starter-parent    2.1.8.RELEASE        com.example  demo  0.0.1-SNAPSHOT  demo  Demo project for Spring Boot  war      war-demo        1.8              org.springframework.boot      spring-boot-starter-web              org.springframework.boot      spring-boot-starter-tomcat      provided              org.springframework.boot      spring-boot-starter-test      test        

3、修改启动类方法 DemoApplication.java

继承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;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;@SpringBootApplication@RestControllerpublic class DemoApplication extends SpringBootServletInitializer {  protected SpringApplicationBuilder configure(SpringApplicationBuilder application){    return application.sources(DemoApplication.class);  }  public static void main(String[] args) {    SpringApplication.run(DemoApplication.class, args);  }  @RequestMapping("/")  public String test(){    return "test";  }}

关于SpringBoot2中怎么构建可部署的war包问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注创新互联行业资讯频道了解更多相关知识。


当前文章:SpringBoot2中怎么构建可部署的war包
当前网址:http://kswjz.com/article/ggejee.html
扫二维码与项目经理沟通

我们在微信上24小时期待你的声音

解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流