0

I'm using spring boot 1.3.3 and what I have is mainly a REST api project, I want to serve some html pages on this application and I've been having troubles the whole day trying to configure it up.

I was able to serve static pages but it looks like Velocity is resolving the views because its view resolver has priority. So I had to change velocitys view resolver suffix from vm to html (or else ill have to change the extension of my html pages), like so, spring.velocity.suffix=.html in application.properties

This is how I managed to serve forgot_password.html that resides in /resources/

@Controller
@RequestMapping(value = "/")
public class SiteController {
    @RequestMapping(value = "forgot_pass", method = RequestMethod.GET)
    public String forgotPassword() {
        return "forgot_password";
    }
}

If i remove velocity from my project, I can't host static html pages (I don't know why, probably an obvious reason but i'm a bit ignorant on this) but looks like spring tries to point to an api end-point, while i'm actually trying to point to a resource file.

Is there a way to serve static html pages without using @EnableWebMvc or any templating technology (like velocity/thyemleaf)?

Thanks

edit: pom dependencies

prettyvoid
  • 3,446
  • 6
  • 36
  • 60
  • If you have defined a `@RestController` the return value is the body of the response, not the name of a view. Also your templates live in `src/main/resources/templates` and your static resources in `/src/main/resources/static`. – Stephane Nicoll Mar 03 '16 at 08:00
  • The controller I'm using to serve static webpages is not a `@RestController` but a `@Controller`. If I put my html page inside `src/main/resources/static`, I get a 404 Not found, but if I place the html page inside `src/main/resources` directly Spring is able to find the page and it gets displayed. Also if I remove Velocity from my dependencies, I can no longer display the page whatsoever. Can you shed some light on these 2 issues? How can I let Spring locate my html pages inside `/resources/static` and why it's not working when I remove velocity? I added my pom as a link. Thanks Stéphane – prettyvoid Mar 03 '16 at 12:26
  • Adding a view resolver or tomcat-embed-jasper if you are using tomcat might resolve the issue for you. Give it a try. `http://stackoverflow.com/questions/29953245/configure-viewresolver-with-spring-boot-and-annotations-gives-no-mapping-found-f` – minion Mar 03 '16 at 12:45

0 Answers0