Reputation: 25397
Note: The code can be found here: https://github.com/silentsnooc/ema-server
So, I am cleaning up a quite messy project in which I try to serve static content as well as a small REST API. However, the application gets started as any other:
@SpringBootApplication
public class Server {
public static void main(String[] args) {
SpringApplication.run(Server.class, args);
}
}
The REST API works for me but the web client is not. I've moved the web client resources into src/main/resources/static/
However, if I visit http://localhost:8080 what I get is 405 (Request method 'GET' not supported).
org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'GET' not supported
at org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping.handleNoMatch(RequestMappingInfoHandlerMapping.java:207) ~[spring-webmvc-4.3.6.RELEASE.jar:4.3.6.RELEASE]
at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.lookupHandlerMethod(AbstractHandlerMethodMapping.java:374) ~[spring-webmvc-4.3.6.RELEASE.jar:4.3.6.RELEASE]
at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.getHandlerInternal(AbstractHandlerMethodMapping.java:314) ~[spring-webmvc-4.3.6.RELEASE.jar:4.3.6.RELEASE]
at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.getHandlerInternal(AbstractHandlerMethodMapping.java:61) ~[spring-webmvc-4.3.6.RELEASE.jar:4.3.6.RELEASE]
at org.springframework.web.servlet.handler.AbstractHandlerMapping.getHandler(AbstractHandlerMapping.java:352) ~[spring-webmvc-4.3.6.RELEASE.jar:4.3.6.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.getHandler(DispatcherServlet.java:1145) ~[spring-webmvc-4.3.6.RELEASE.jar:4.3.6.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:936) ~[spring-webmvc-4.3.6.RELEASE.jar:4.3.6.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897) ~[spring-webmvc-4.3.6.RELEASE.jar:4.3.6.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) [spring-webmvc-4.3.6.RELEASE.jar:4.3.6.RELEASE]
...
I do not understand what's missing - maybe I got the folder structure wrong?
Please let me know if you need any further information from my side.
Upvotes: 0
Views: 1067
Reputation: 1358
As stated here @RestController
is itself annotated with @ResponseBody
which makes the response of your RequestMapping
methods to be their return value. In your case that is the index.html
string you're seeing in the web browser.
Replacing the @RestController
annotation with @Controller
should do the trick.
As for your error you have another class WordEmbeddingRestController
which defines mappings for "/" as well, as "/" (or "" to be exact) is the default path value. Removing the @RestController
annotation from this class will enable you to GET the desired html file.
Ignore that, GET
is the default method if non was specified
For your edit:
You have to add the method you want to support to the @RequestMapping
annotation for each of your methods. See this for more information. As an example:
@RequestMapping(path = "/", method = RequestMethod.GET)
public String index() {
return "index.html";
}
Instead of using @RequestMapping
with an explicit method you can also use shorthand annotations like @GetMapping
and @PostMapping
. Using these would reduce your code to someting like this:
@GetMapping("/")
public String index() {
return "index.html";
}
Upvotes: 2