springboot 项目生成war包但是部署到服务器上地址正确,但是访问是404 解决办法: 1:修改pom文件,去除掉内置tomcat,并且依赖servlet-api
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>org.springframework.boot:spring-boot-starter-tomcat:1.5.7.RELEASE</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
2:修改springboot启动类 ,继承springbootservletinitializer类,并且重写 configure方法
@SpringBootApplication
public class BlogApplication extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return super.configure(builder);
}
public static void main(String[] args) {
SpringApplication.run(BlogApplication.class, args);
}
}
4:重新生成war包上传服务器
5:如果还是404,请检查本地能够运行的tomcat和服务器上是否一致,是否服务器上tomcat版本过低
6: 检查java版本是否一致
7: 检查服务器是否开放了当前使用的端口号
|