war package creation

 

1. First embodiment packaged under modified pom.xml

    <groupId>com.test</groupId>
    <artifactId>springboot</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <name>springboot</name>
    <description>Demo project for Spring Boot</description>

  

2. Add dependent servlet-api

<!--添加servlet-api的依赖-->
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.1.0</version>
    <scope>provided</scope>
</dependency>

  

 3. Remove springboot embedded tomcat module

Because you are outside tomcat use of this package is removed so good. First, in order not to cause unnecessary conflict, the second is war can break out of the bag a little small

 

<dependency> 
    <groupId> org.springframework.boot </ groupId> 
    <artifactId> the Spring-the Boot-Starter-Web </ artifactId> 
    <-! ignore embedded tomcat, packaged deployed to tomcat. Note * When running locally should ignore this section of the introduction of a comment out, or else the project will not start -> 
    <Exclusions> 
        <Exclusion> 
            <groupId> org.springframework.boot </ groupId> 
            <artifactId> the Spring-the Boot-Starter - tomcat </ the artifactId> 
        </ Exclusion> 
    </ Exclusions> 
</ dependency>

4. There are special important step that [inheritance SpringBootServletInitializer configure and override this method to check their own reasons]

A method is: directly modifying startup class

@SpringBootApplication
public class WxWebApplication extends SpringBootServletInitializer{

	public static void main(String[] args) {
		SpringApplication.run(WxWebApplication.class, args);
	}

	@Override
	protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
		return builder.sources(WxWebApplication.class);
	}
}

  The second is this: in the same directory to start a new class of ServletInitializer class that inherits SpringBootServletInitializer configure and override this method

 

public class ServletInitializer extends SpringBootServletInitializer {

	@Override
	protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
		return application.sources(WebApplication.class);
	}

}

  Details: http: //www.manongjc.com/article/28670.html

Guess you like

Origin www.cnblogs.com/ynhk/p/11273872.html