1.pom要有所改动(关于servlet的)
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-starter-tomcat
org.springframework.boot
spring-boot-starter-tomcat
provided
javax.servlet
javax.servlet-api
3.1.0
最后一句packaging要加上
springboot
0.0.1-SNAPSHOT
springboot
Demo project for Spring Boot
war
plugin加上这个,finalname自己取,打包完成后的war名
org.apache.maven.plugins
maven-resources-plugin
2.6
tmall_springboot
2.启动类配置
加上注解@ServletComponentScan,并且继承SpringBootServletInitializer并重写方法
@ServletComponentScan
public class SpringbootApplication extends SpringBootServletInitializer {
@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,可能是路径没配好。注释掉原来的路径,新加一条static路径。
#上下文地址(打包war要注释掉) #spring.mvc.servlet.path=/tmall_springboot(原来的springboot路径) #上下文地址(打包war) spring.mvc.static-path-pattern=/**



