You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Boot请求返回404错误求助:按教程操作仍未解决

Troubleshooting 404 Error in Your Spring Boot App

Hey there! Let's dig into why you're hitting that frustrating 404 even though your server starts up fine. I spotted a couple of key issues in your code that are likely causing this:

1. Invalid Syntax in @ComponentScan

Looking at your main class, the @ComponentScan annotation has extra angle brackets around the package path:

@ComponentScan(basePackages = "<io.javabrains.springbootstarter.hello>")

Those <> are invalid syntax here—Spring can't parse the package name correctly, so it fails to scan and register your HelloController.

Fix it by removing the angle brackets:

@ComponentScan(basePackages = "io.javabrains.springbootstarter.hello")

Actually, the @SpringBootApplication annotation already includes @ComponentScan by default—it automatically scans the package where your main class lives and all its sub-packages.

If your HelloController is in the same package as CourseApiApp or a sub-package of it, you can completely remove the @ComponentScan annotation to simplify your code:

@SpringBootApplication
public class CourseApiApp {
    public static void main(String[] args) {
        SpringApplication.run(CourseApiApp.class, args);
    }
}

3. Double-Check Package Structure

Make sure your HelloController is placed in a package that Spring can scan. For example:

  • If your main class is in io.javabrains.springbootstarter, your controller should be in io.javabrains.springbootstarter or io.javabrains.springbootstarter.hello (a valid sub-package).

4. Verify the Request URL

After fixing the above, restart your server and confirm you're accessing the correct URL:
http://localhost:8080/hello (assuming you're using the default port 8080—adjust the port if you changed it in application.properties).

Give these fixes a try, and your /hello endpoint should start returning "Hi" as expected!

内容的提问来源于stack exchange,提问作者Bartłomiej Matyjaszczyk

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 07:46:10