When I send the GET request to the mapping "/", I receive NotFound errors.
Here is my @Controller class:
@Controller
public class Store {
@RequestMapping(value = "/", method = RequestMethod.GET)
public String home() {
return "home";
}
}
Here is my application.properties file which specifies the location of the view files:
spring.mvc.view.prefix=/view/
spring.mvc.view.suffix=.html
And for reference, here is my home.html file:
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Store</title>
</head>
<body>
<h1>Hello</h1>
</body>
</html>
My home.html file is in the view folder within the webapp folder.
To my understanding when sending the request to localhost:8080 the home page should load, I am perplexed that it is not the case.
Any help at all will be greatly appreciated. Thanks.
UPDATE:
So I managed to get it working by renaming the HTML file from home.html to index.html and moving it to the webapp folder. How is it now working after I rename it and move it to the base web folder???? Surely the name is irrelevant and I already specified the prefix and suffix to act as the view resolver to point to the directory of the view files.
This is working due to Springs default behaviour of mapping our index.html page as the landing page, but the method handler is still never called...
FINAL UPDATE:
I have recreated this project in Eclipse (previously created in STS4) and it is working, there was no change needed. I assume it was due to my configuration of STS4. So to anyone that may experience this issue in the future or something similar, double check your configuration of your IDE, it may not always be your code. :)
Thank you all for your input.
Here are a few things to look into:
Check that your home.html file is in the correct folder. In your application.properties file, you specified that the view files are in the "/view/" folder within the webapp folder. As a result, ensure that your home.html file is in the "/webapp/view/" folder.
Check to see if your application is set up correctly to serve static resources. If not, add the line below to your application. file with properties:
spring.mvc.static-path-pattern=/resources/**
spring.resources.static-locations=classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/
This configuration ensures that your application serves static resources from the locations specified.
@RequestMapping(value = "/", method = RequestMethod.GET)
public String home() {
return "/view/home.html";
}
This should make it possible for your application to find the home.html file.