美文网首页
SpringBoot项目改为war包,并使用tomcat发布

SpringBoot项目改为war包,并使用tomcat发布

作者: 至爱雅鸿_e631 | 来源:发表于2019-09-29 15:33 被阅读0次

1.pom文件修改

修改tomcat包引入

<!--目的是打包时不包含此包-->
<dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-tomcat</artifactId>
      <scope>provided</scope>
</dependency>

修改打包类型

 <groupId>com.example</groupId>
  <artifactId>fun.pay</artifactId>
  <version>0.0.1-SNAPSHOT</version>
<!--  <packaging>jar</packaging>-->
  <packaging>war</packaging>

2.修改入口类

继承org.springframework.boot.web.servlet.support.SpringBootServletInitializer类,并重载configure方法

@SpringBootApplication
@MapperScan("com.fun.pay.mapper.*")
public class SpringBoot extends SpringBootServletInitializer {

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

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

为什么修改这个类?

Note that a WebApplicationInitializer is only needed if you are building a war file and deploying it. 
If you prefer to run an embedded web server then you won't need this at all.
翻译:
注意,如果您正在构建WAR文件并部署它,则需要WebApplicationInitializer。
如果你喜欢运行一个嵌入式Web服务器,那么你根本不需要这个。

3.修改yml文件配置

server:
  port: //注释掉端口8090,默认使用tomcat的端口

4.打包

mvn clean package -Dmaven.test.skip=true

相关文章

网友评论

      本文标题:SpringBoot项目改为war包,并使用tomcat发布

      本文链接:https://www.haomeiwen.com/subject/jryquctx.html