spring-boot项目 war包发布
1.配置springboot主类(带有@SpringBootApplication)继承SpringBootServletInitializer,同时重写configure方法 @SpringBootApplication
public class Application extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
public static void main(String[] args) throws Exception {
SpringApplication app = new SpringApplication(Application.class);
app.run(args);
}
}
2.
修改pom.xml中package
jar --> war
3.在pom.xml中添加依赖
org.springframework.boot
spring-boot-starter-tomcat
provided
org.springframework.boot
spring-boot-legacy
1.0.2.RELEASE
4.配置web.xml Older Servlet containers don’t have support for the
ServletContextInitializer
bootstrap process used in Servlet 3.0. You can still use Spring and Spring Boot in these containers but you are going to need to add a web.xml
to your application and configure it to load an ApplicationContext
via a DispatcherServlet
.如果是比较早的servlet容器(低于Servlet 3.0),可能不支持ServletContextInitializer,这时我们需要给项目配置一个web.xml,并将配置类加载进项目。以下是spring官方给出的方案:
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
contextConfigLocation
com.Application
dispatcherServlet
org.springframework.web.servlet.DispatcherServlet
contextAttribute
【spring-boot项目 war包发布】org.springframework.web.context.WebApplicationContext.ROOT
dispatcherServlet
5.参考地址http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-create-a-deployable-war-file
推荐阅读
- 17|17 关山松 第二课作业#公众号项目# D20
- RxJava|RxJava 在Android项目中的使用(一)
- Hacking|Hacking with iOS: SwiftUI Edition - SnowSeeker 项目(一)
- 靠QQ月入上万灰色暴利偏门的项目
- spring|spring boot项目启动websocket
- vuex|vuex 基础结构
- 区块链开发平台(以太坊)
- VM|VM ware 的 harbor 私有仓库搭建 (Ubuntu16.04)
- 如何在手机上查看测试vue-cli构建的项目
- django2.2|django2.2 一般项目步骤(初步)