I’m encountering an issue with my Spring Boot application. Whenever I attempt to access my designated endpoint, I receive a whitelabel error instead of the page I expect.
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class Destination {
@RequestMapping("/selectdestination")
public String displayDestination(Model model) {
model.addAttribute("selection", "destination");
return "destination";
}
}
The error I see is as follows:
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
There was an unexpected error (type=Not Found, status=404).
No message available
I have been trying to resolve this issue for several hours now but I’m unable to find the problem. I just want the page to show a simple message, but it’s not functioning as it should.
The whitelabel error typically indicates that Spring Boot cannot locate your view file. While danielr’s advice about template engine setup is crucial, it’s also essential to examine your project’s directory structure. I faced a similar scenario when my main application class was not positioned in the root package or above the controller package, causing Spring’s component scanning to overlook my controller entirely. Additionally, scrutiny of your application.properties file is prudent, as the view resolver can be easily misconfigured due to recent changes. Consider adding spring.mvc.view.prefix=/templates/ and spring.mvc.view.suffix=.html to your configuration—though these settings shouldn’t usually be required with a properly configured Thymeleaf setup, they may help in troubleshooting. If the issue persists, set up a simple endpoint that returns a string instead of a view name, which will help validate whether your controller mapping is functioning as intended. This approach can clarify if you’re dealing with a routing problem or an issue with view resolution.
Quick sanity check - are you hitting the right URL? I’ve debugged this exact error for teammates who were hitting /destination instead of /selectdestination.
Run mvn clean compile or whatever build tool you’re using. I’ve seen this when stale class files hang around after package refactoring.
If you’re still stuck, temporarily change your controller method to return a plain string:
@RequestMapping("/selectdestination")
@ResponseBody
public String displayDestination() {
return "Controller works fine";
}
This tells you right away if the controller mapping’s broken or if it’s a view resolution problem.
Once that works, remove @ResponseBody and make sure you’ve got an actual destination.html file with basic content like <h1>Test</h1>. Don’t overthink the HTML at first.
I’ve wasted too many hours chasing complex solutions when it was just a typo in the file name or missing the template dependency.
Had this exact issue migrating an old Spring project to Boot. The fix was embarrassingly simple - my controller was getting scanned fine, but I’d completely forgotten to add a template engine starter dependency. Spring Boot was looking for “destination” as a view but had nothing to process it with. Besides the Thymeleaf setup others mentioned, make sure your main class has @SpringBootApplication. Without it, auto-configuration breaks and view resolution fails silently even with the right dependencies. Another thing that got me - check if your template file has weird encoding or permission issues. I had destination.html sitting right there in src/main/resources/templates/ but filesystem problems made Spring think it didn’t exist. Create a basic test template with just plain HTML first to rule out content issues. Also verify your IDE actually copies resources when building. I’ve seen Maven configs that just skip resource copying entirely.
quick check - are u running the app from the right directory? had this same issue when my working directory was wrong and spring couldn’t find templates even tho everything looked fine. also try hitting localhost:8080/selectdestination directly in ur browser instead of going thru redirects - sometimes the path gets messed up
Second, make sure “destination.html” exists in the right spot. For Thymeleaf it goes in src/main/resources/templates/destination.html.
I’ve seen people dump templates in random folders then wonder why Spring can’t find them. The framework’s pretty strict about paths.
If both look good, add some debug logging to see what Spring’s actually looking for:
logging.level.org.springframework.web=DEBUG
This shows you exactly where Spring’s hunting for your template file. Saved me hours of guessing when I hit a similar issue with a microservice last year.