美文网首页
SpringBoot项目通过Idea打war包

SpringBoot项目通过Idea打war包

作者: 佛系疯子 | 来源:发表于2020-04-17 00:59 被阅读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....

相关文章

网友评论

      本文标题:SpringBoot项目通过Idea打war包

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