本文主要是介绍springboot部署war包,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
文章目录
- 添加依赖
- 添加war包maven插件
- SpringBootServletInitializer
- 打包
添加依赖
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-tomcat</artifactId><scope>provided</scope>
</dependency>
注:不建议在spring-boot-starter-web中排除tomcat,因为还要单独引入servlet-api
添加war包maven插件
<plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-war-plugin</artifactId><version>2.2</version><configuration><failOnMissingWebXml>false</failOnMissingWebXml></configuration>
</plugin>
注:打包时报错,Error assembling WAR: webxml attribute is required,这是因为使用Spring开发,默认把所有的静态资源+界面view都放在resources下了,因此,webapp都不复存在了,更何况/WEB-INF和/WEB-INF/web.xml,解决方案,在maven-war-plugin中添加属性failOnMissingWebXml并设置为false
SpringBootServletInitializer
启动来继承SpringBootServletInitializer类并重写configure方法
@SpringBootApplication
@MapperScan(basePackages = {"com.shopping.dao"})
public class ShoppingApplication extends SpringBootServletInitializer {@Overrideprotected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {return builder.sources(ShoppingApplication.class);}public static void main(String[] args) {SpringApplication.run(ShoppingApplication.class,args);}
}
打包
mvn clean package -Dmaven.test.skip=true
这篇关于springboot部署war包的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!