How can I resolve the white label error (404) for my Spring Boot application running on localhost:8080?

I’ve been troubleshooting for quite some time and can’t figure out why my Spring Boot app keeps throwing a white label 404 error when trying to access localhost:8080. Despite no errors showing up in the console when I run the application, it seems like I can’t reach any of my endpoints.

I placed my main class and controller in separate packages, and I’ve already added the @ComponentScan annotation. I also thought that adding a webapp directory might help, but it hasn’t made a difference. I’ve verified that all necessary mappings are in my controller. Below is my pom.xml configuration:

<project xmlns="http://maven.apache.org/POM/4.0.0">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.5.RELEASE</version>
    </parent>
    <groupId>com.example</groupId>
    <artifactId>Kamerat</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>Kamerat</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>1.8</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-mongodb</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

Could someone guide me on what might be causing the problem? I would really appreciate any assistance!

try placing your main app into the root package. spring boot scans from the main class down, so if your controller is in a sibling package, it won’t be recognized. also, enable logging.level.web=DEBUG to troubleshoot what endpoints are being registered.

Check if you’re hitting the right URL. I’ve seen this when people go to localhost:8080 directly but their controllers don’t have a root mapping.

Try localhost:8080/actuator/mappings to see what endpoints Spring registered. If it works, you’ll get JSON showing all your mapped endpoints.

I run into this constantly - make sure your controller has @RestController or @Controller. I’ve wasted embarrassing amounts of time forgetting that basic annotation.

Enable debug logging with logging.level.org.springframework.web=DEBUG in application.properties. Shows exactly what Spring’s mapping during startup instead of guessing.

If that doesn’t help, post your controller code. The pom looks fine but I can’t pinpoint the issue without seeing your actual controller and main class.

Yeah, Spring Boot won’t serve anything at localhost:8080 unless you map something to the root. I’ve been there - everything looks right but you forgot to handle /. If your controller only has /api/something mapped, hitting localhost:8080 gives you that whitelabel error since nothing’s mapped to root. Try localhost:8080 plus whatever path you mapped in your controller. Also check your methods are public - Spring ignores private methods even with correct annotations, and that’s bitten me before. Your Maven deps look fine, so it’s definitely routing or method visibility, not missing libraries.

Had this exact issue last month - drove me crazy for hours. It’s probably your package structure even though you have @ComponentScan. Your main application class needs to be above your controller packages in the hierarchy. Spring Boot’s default scanning only hits packages at the same level or below your main class. Also double-check that your controller methods have @RequestMapping or @GetMapping annotations, not just at the class level. What helped me debug was adding server.error.whitelabel.enabled=false to application.properties - you’ll get actual error messages instead of that useless whitelabel page. Your pom.xml looks fine, so it’s definitely scanning or mapping.