在一个简单的Spring Boot应用中遇到的404错误

后端开发 2026-07-09

我用Spring Boot开发了一个小应用。

请求时出现了400和 404错误。

我先从一个简单的出发点开始。我启动应用程序,以下是我的控制器。

   @Controller
   public class SubscriptionController {
 
       private final SubscriptionService subscriptionService;
 
       @Autowired
       public SubscriptionController(SubscriptionService subscriptionService){
           this.subscriptionService = subscriptionService;
       }
 
       @GetMapping()
       public String hello() {
           return "hello world";
       }

and request http://localhost:8080 return a 404 error
ping send back data

I tried with the name of application. In my pom.xml I have "<name>galaxion</name>" and in my application.properties I have "spring.application.name=galaxion"

the request http://localhost:8080/galaxion return a 404 error

解决方案

在你的 application.properties 中,你应该设置 server.servlet.context.path

server.port=8081
server.servlet.context.path=/galaxion

如果你声明了: server.port=8081,那么应在端口 8081 上查找它。

http://localhost:8081/galaxion

站内所有文章版权归属LeftHeroAI导航站,无授权禁止任何主体转载、抄袭、复制内容,亦不得私自架设镜像站点。一经侵权,本站将通过法律途径追责。

相关文章