This is the fourth Post in my series Developing a web application with Spring Boot, AngularJS and Java 8.
Most of the things i’ve done in AngularJS are pretty standard (i guess), but have a look at the sources yourself: bikings js.
Therefor i want to highlight just a few things that made Spring Boot play nicely with AngularJS:
I wanted biking.michael-simons.eu as well as biking.michael-simons.eu/about too work when entered in the address bar or followed through a link. To achieve this, i’m using AngularJS in HTML5 mode. Really, for this project i couldn’t care less about browser which don’t support this:
The whole html “application” lives in webapp/public/index.html which is served as a static resource by Spring Boot without any further server interaction.
To create “routes” for all URLs in app.js, i’ve created a super simple @Controller:
This forwards all mapped urls to the static resource without any further view resolving. Nice!
Spring Boot has excellent support for WebJars and automatically creates resolvers for them. Using web jars i can manage all dependencies for AngularJS and co. with Maven (yeah, i’m still using maven… ):
and for example
And in index.html
I’m using plain old http basic auth. Yes, i do know that the password is transmitted in plain text but for this app and this purpose, i just don’t care. For your interest, here’s the Spring Security configuration for stateless http basic auth:
I’ve got to disable csrf protection because i don’t want to handle that in AngularJS and also, i’ve disable frame headers because the application acts as an oembed provider with frames.
I didn’t protect the whole app, but only backend methods with write access through annotations which is enabled via @EnableGlobalMethodSecurity and looks like:
Using @RestController from AngularJS
The above quoted method can easily be used from AngularJS:
Fancy things created with AngularJS
I’m not using AngularJS not long enough to rate this, but i really like the automatically refreshing about page which is created using through highcharts-ng and the nice OpenLayers integration for the tracks, written by myself: track-map-ng (OpenLayers), see an example here: Aachen – Domburg.
Rewriting this existing application from scratch (apart from the database model, that was fine), was real fun. Not only i could test and enjoy many new Java 8 features, but starting fresh, using well designed frameworks like Spring, Spring Boot and Spring Data JPA fixed many things for me i used to do wrong, sometimes because of some cargo cult i hand in mind, sometimes because i just didn’t get them right from the start.
Look at some other projects of mine, i have no doubt that Boot is also a good choice for writing bigger applications, maybe with a more classical frontend, either JSP or Thymeleaf based.
Also: Java is not dead yet, in 2014 more far from than ever.
Thanks for reading so far.