(1)<packaging>war</packaging> (2)新写一个类,Servlet配置。
import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
@SpringBootApplication() public class ServletApplication extends SpringBootServletInitializer {
public static void main(String[] args) throws Exception { SpringApplication.run(xxxxApplication.class, args); } }
还有人说可以这样写,省一个类
@SpringBootApplication public class MainApp extends SpringBootServletInitializer {
public static void main(String[] args) { SpringApplication.run(MainApp.class,args); }
@Override protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { return builder.sources(MainApp.class); } }
嗯,这样写比较好。 (3)去除Spring Boot的web-starter自带的tomcat
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> </exclusion> </exclusions> </dependency>
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency>
好像tomcat几个jar包排除不掉呢,怎么回事啊。
(4)springboot的maven build插件不用动。 <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> -------------------------------- 报错:ClassNotFoundException: javax.servlet.GenericFilter 这个是没把内嵌tomcat去掉。
报错:log4j-slf4j-impl cannot be present with log4j-to-slf4j 这俩包引用一个就行,想办法排除掉一个吧。
|