Reputation: 339
I am trying to run an application so I can test it locally but currently I am having issues.
I am using gradle and following this tutorial
https://spring.io/guides/gs/serving-web-content/
However, I finish the tutorial and run this command :
./gradlew bootRun
The application starts but I can't hit the end point.
It throws the following error:
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Fri Dec 16 16:25:06 GMT 2016
There was an unexpected error (type=Not Found, status=404).
No message available
Any idea how to fix this?
package conf;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
*/
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Greeting Class
package controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
/**
*/
@Controller
public class GreetingController {
@RequestMapping("/greeting")
public String greeting(@RequestParam(value="name", required=false, defaultValue="World") String name, Model model) {
model.addAttribute("name", name);
return "greeting";
}
}
Thanks
Upvotes: 0
Views: 1908
Reputation: 35864
I believe it is because of your package structure. Based on the code you've given, your Application
class can't see GreetingController
because they are in sibling packages. @SpringBootApplication
needs to be able to component scan same package and child packages. It can't see sibling packages. So GreetingController
never gets wired up.
Won't work:
com.conf.Application
com.controller.GreetingController
Will work:
com.conf.Application
com.conf.controller.GreetingController
Upvotes: 2