SpringBoot项目通过Idea打war包

2020-04-17  本文已影响0人  佛系疯子

首先,查看当前主项目的打包方式,查找pom文件中的packaging属性,

然后,需要在pom.xml中添加依赖,表明tomcat是外部提供:
< dependency>

      <groupId>org.springframework.boot

    <artifactId>spring-boot-starter-tomcat

    <scope>provided

</dependency>

接着,新建web.xml,直接通过idea创建就好,注意要放到webapp文件夹下

最后,创建一个Initializer类继承自SpringBootServletInitializer,并重写configure方法且这个类应该与项目的Application在同一级目录下。

这些操作之后,就可以打包了,可以通过maven命令打包,也可通过idea的maven插件打包。

注意:在pom中添加的依赖是表明tomcat是外部提供,而开发的时需要注释掉该依赖,否则idea启动项目时会报错 Unable to start web server; nested exception is org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean....

上一篇 下一篇

猜你喜欢

热点阅读