Spring Boot新手启动Pivotal Server后遇Chrome HTTP 404错误求助
Hey there, let's work through this 404 issue step by step—since you're new to Spring Boot and Pivotal Server, we'll start with the basics to make sure nothing's missed.
1. 先确认技术栈兼容性
First off, Pivotal tc Server 3.2 is built on top of Tomcat 7. If your Spring Boot project uses version 2.x or higher, that's a core problem because Spring Boot 2.x requires Tomcat 8.5 or newer.
- Check your
pom.xml(orbuild.gradle) for the Spring Boot version. If it's 2.x+, you have two valid options:- Downgrade Spring Boot to 1.x (fully compatible with Tomcat 7)
- Upgrade your Pivotal Server to a newer release (like 4.x+) that supports Tomcat 8.5+
2. 确保项目打包为WAR格式
Spring Boot defaults to JAR packaging, but Pivotal Server (a servlet container) needs WAR files to deploy properly:
- Open your
pom.xmland set<packaging>war</packaging>(replace the defaultjar) - Add a
ServletInitializerclass alongside your main Spring Boot application class to enable deployment to a servlet container:
Make sure this class is in the same package as your main app class so it gets scanned correctly.public class ServletInitializer extends SpringBootServletInitializer { @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(YourApplicationClassName.class); } }
3. 正确部署项目到Pivotal Server
Let's walk through the deployment steps in STS to avoid misconfiguration:
- Right-click your project → Run As → Run on Server
- Select your configured Pivotal Server 3.2 from the list, then click Next
- Move your project from the "Available" list to "Configured" (this tells the server to deploy it)
- Click Finish and wait for the server to start fully—keep an eye on the Console tab for any startup errors.
4. 验证你的访问路径
A lot of 404s happen just because the URL is wrong:
- When deploying a WAR, the default context path is your WAR file's name. So if your WAR is
my-spring-app.war, the base URL ishttp://localhost:8080/my-spring-app/ - Check your controller's
@RequestMappingannotations. For example, if you have:
You need to visit@RestController public class HelloController { @RequestMapping("/greet") public String greet() { return "Hello from Spring Boot!"; } }http://localhost:8080/my-spring-app/greetto see the response. - Double-check that your main application class has the
@SpringBootApplicationannotation—this enables component scanning, so your controllers get picked up.
5. 从服务器日志里找线索
If everything above checks out, look at the server logs to find hidden issues:
- In STS, check the Console tab while the server starts. Look for errors like:
ClassNotFoundException: Means a dependency is missing from your WARBeanCreationException: Indicates a Spring configuration error- Port conflict messages: If 8080 is in use, edit your server settings in STS (double-click the server in the Servers view) to use a different port like 8081.
- You can also find log files in your Pivotal Server installation directory under
logs/(look atcatalina.logorlocalhost.logfor detailed errors).
6. 用极简项目做测试
If you're still stuck, create a super simple Spring Boot project to isolate the issue:
- Use STS's Spring Starter Project wizard, select only the "Web" dependency
- Package it as a WAR, deploy it to Pivotal Server, and test the basic endpoint. If this works, the problem is likely in your original project's configuration (like custom filters, database setups, etc.).
内容的提问来源于stack exchange,提问作者Soumadip Chakraborty

