Serving angular2 content from Spring Boot application

Recently I had to ship an Angular2/Angular4 application within a Spring boot WAR packaged application and I was having some issues when dealing with the the urls in the angular routes, since it goes through the DispatcherServlet I was getting 404 all over the place

There are a few ways to handle this, below is my preferred solution :

public class Angular2ViewController {

    @RequestMapping({"/books", "/login", "/admin", "/logout", "/configure"})
    public String index() {
        return "forward:/index.html";


There you go, as easy as that

The inconvenience about this solution is that you have to maintain a set of urls in your controller also

No comments:

Post a Comment

OSX show used ports or listening applications with their PID

On OSX you can display applications listening on a given port using the lsof the commands described below will show listening application...