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官方给出的方案:


         xmlns="http://java.sun.com/xml/ns/javaee"
         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">

    i-test-war
    

contextConfigLocation

com.Application




org.springframework.boot.legacy.context.web.SpringBootContextLoaderListener

    
   
        dispatcherServlet
        org.springframework.web.servlet.DispatcherServlet

contextAttribute
org.springframework.web.context.WebApplicationContext.ROOT

        1
   

   
        dispatcherServlet
        /
   


5.参考地址 
http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-create-a-deployable-war-file

你可能感兴趣的:(Spring)