I have no idea what we're doing wrong here. I'm trying to set up a single page Spring MVC project so I can look into things. I have a single screen, greeting.html that I'm trying to load. Here's my controller class to load it:
@Controller
public class GreetingController {
@GetMapping("/greeting")
public String getGreeeting(@RequestParam(name="name", required=false, defaultValue="World") String name, Model model) {
model.addAttribute("name", name);
return "greeting";
}
}
This works fine when greeting.html is in /resources/templates/greeeting.html. However, I'd like it behind a WEB-INF folder. I've tried placing it in WEB-INF/views/greeting.html and webapp/WEB-INF/views/greeting.html. I then try and use an InternalResourceViewResolver as I've read online:
@Bean
public InternalResourceViewResolver viewResolver() {
InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
viewResolver.setPrefix("/WEB-INF/views/");
viewResolver.setSuffix(".html");
return viewResolver;
}
From my understanding, this should allow it to find greeting.html behind one of my WEB-INF folder setups. However, when I go to localhost:8080/greeting, I get a 404 along with the following message in the console:
WARN 1439 --- [nio-8080-exec-1] o.s.w.s.r.ResourceHttpRequestHandler : Path with "WEB-INF" or "META-INF": [WEB-INF/views/greeting.html]
I'm at a complete loss as to what's even going on or how to fix it, every single tutorial online does this exact thing and has no problems, I can't seem to find anyone online with this same issue. Any guidance at all would be helpful here.