1.pom要有所改动(关于servlet的)
<!-- springboot web(打包war) -->
<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>
<!-- Servlet API(打包war) -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
最后一句packaging要加上
<artifactId>springboot</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>springboot</name>
<description>Demo project for Spring Boot</description>
<!-- 打包war -->
<packaging>war</packaging>
plugin加上这个,finalname自己取,打包完成后的war名
<!--打包war-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
</plugin>
</plugins>
<!--打包war-->
<finalName>tmall_springboot</finalName>
2.启动类配置
加上注解@ServletComponentScan/*打包war*/,并且继承SpringBootServletInitializer并重写方法
@ServletComponentScan/*打包war*/
public class SpringbootApplication extends SpringBootServletInitializer {
/*打包war*/
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(SpringbootApplication.class);
}
public static void main(String[] args) {
SpringApplication.run(SpringbootApplication.class, args);
}
}
3.properties配置
如果访问网址出现404,可能是路径没配好。
#上下文地址(打包war要注释掉)
#spring.mvc.servlet.path=/tmall_springboot(原来的springboot路径)