I developed a simple Hello World Spring MVC Web Application using Spring Boot (Spring Initializr - start.spring.io). I chose the following options at Spring Initializr:
Clicked on Generate to download the starter app, extracted it and added:
Issue: When I try to hit the action method from the browser using the following url I get "Whitelabel Error Page": http://localhost:8080/helloWorld
Can you please tell me what I am missing?
GitHub Repo: https://github.com/angunda/hello-world-spring-web-app
I tried issuing GET /localhost:8080/helloWorld in InteliJ's HttpClient and got 404 NOT FOUND error instead of the helloWorld.html file.
I also issued the request from chrome using http://localhost:8080/helloWorld, however, got Whitelabel Error Page instead of helloWorld.html page
If you want Spring to scan for your controller then move your MainController.java
from
package controller;
to
package com.example.HelloWorldWebApp.controller;
If you want Spring to scan for your controller, but if you want to keep your controller in the current package add this in your main class annotation
@SpringBootApplication(scanBasePackages = "controller")
Both will yield the same result.
The first approach works the way that spring will start scanning all subpackages starting from the package where your main class is located
So if your main class is in
package com.example.HelloWorldWebApp;
It will scan for all packages within it like
package com.example.HelloWorldWebApp.controller;
package com.example.HelloWorldWebApp.service;
package com.example.HelloWorldWebApp.repo;
But it will not scan anything above it.
That is just controller
in your example