Writing your own Spring Boot starter: wro4j-spring-boot-starter

I’ve been using Wro4j by Alex Objelean for more than 4 years now in a “classic” Spring application, see my post from January 2012 here. The tool has been immensely useful and stable. With my setup at dailyfratze.de, i can disable concatenation and minification during development and have optimized resources during production without much hassle.

Spring Boot is around for nearly 2 years now as well and i used it extensively, on my private projects, for my JUG and also in my company.

There are a lot of really useful starters out there, see the complete list here and i decided to add my own:

The wro4j-spring-boot-starter

Go to the Github project for a full description and short manual on how to use this. The binaries should be in Maven central under the following coordinates:

<dependency>
    <groupId>eu.michael-simons</groupId>
    <artifactId>wro4j-spring-boot-starter</artifactId>
    <version>0.0.7</version>        
</dependency>

I’ve been using the basic code now for 2 months, on the mentioned JUG site and in my company and as always, the Spring Eco system proved to be extremely stable and the people around extremely helpful.

I took the joy to inflect Springs check style settings onto my as Andy pointed out and wrote the starter under the spring-boot-starter-parent which is kinda brutal but gives a very welcome different view on code quality. Furthermore i tried to reach a good test coverage.

The starter will be used in my Spring Boot demo application as well as soon as i have fixed the AngularJS code which is a bit sensitive agains minification.

My favorite toy project, the AngularJS application biking2, based on Spring Boot, has now fully optimized web resources, see this commit.

Together with WebJars, Maven and application properties, Wro4j and now this starter are my preferred tools to stay in control of JavaScript dependencies without resorting to all kinds of package managers. Last year i hoped to be able to speak about that stuff at the JavaLand newcomer track but that didn’t work out. Maybe another conference or JUG and time.

Thanks a lot to my company ENERKO Informatik GmbH for providing the resources to work on that stuff.

Update: Thanks a lot Josh for adding this little starter to This Week in Spring – February 9th, 2016.

| Comments (0) »

02-Feb-16


Spring Boot based site and api for EuregJUG

Since March 2015 Stefan and i are building the EuregJUG Maas-Rhine, a cross-border, english-language Java User Group, located in Aachen. I’ve been blogging about regularly since then (see all posts here) and it’s developing quite well so far. We had 4 well visited talks, nice meetings in between and good conversations.

We noticed some problems, though, especially for managing events. Most Germans use Xing, Dutch and Belgians often use LinkedIn and there’s also Lanyard in the mix. Then there’s java.de running a calendar aggregate which needs an ics somewhere which would also be nice for other people. Our events are free, but for planning resources some kind of registration is a must.

In late 2015 i had the idea of building “our own JUG”. The first feedback was disappointing, though, so i postponed those ideas into my “end of the year” holiday:

  • Basic blogging (for annoucment like this), supporting Markdown or AsciiDoc as input
  • Handling of events (publishing as iCal, crossposting them to XING and Lanyard and certainly registration for those events)
  • Integration of our twitter feed
  • Maybe a mobile app based on JavaFX and Gluon?

Why doing this myself? I’m quite sure i can setup yet another WordPress project, stuff some plugins into it and be good to run, but the time needed would be the same or longer than doing this with the tools I “love”, namely Java inside the Spring eco system. So here we go:

After about 16 to 20 hours after christmas i had the basic site up and running with basic blogging and managing events (calendar, registration). At the moment i use a simple REST api with the awesome Paw as a generic REST client.

That sounds not to much, but the site is fully responsive, has nice database migrations, showcases Springs content negotiating and different views and last but not least, can run locally and without much ado inside “the cloud”, in this case as Stéphane told use in “Building cloud native apps with Spring Boot”.

We’ve made it into Joshs “This Week in Spring column for January 12th, 2016. Thanks a lot!

The site is live at euregjug.eu, the source code is fully available under an Open Source license at github and i’m gonna walk you through some of the interesting and useful parts:

Read the complete article »

| Comments (1) »

14-Jan-16


2015 and gone…

2015 is coming to end, at least regarding work.

The last things i did in December where preparing system specification for a mobile app (targeting BlackBerry) and learning how to create, communicate and maintain good architecture in Munich with Gernot Starke and Peter Hruschka:


With Gernot Starke and Peter Hruschka

Not only i took home a lot of great books, insides, practical tips and nice CPSA-F certificate but a lot of motivation to apply the stuff i learned. The result went live today: biking2, Architecture and API.

The year started with a great 2nd edition of JavaLand with my colleague Silke:


2015-03-24_big

What changed quite a few things was meeting @LukasEder in person. He’s a really nice guy and very convinced and convincing for his product jOOQ. Though it took me some time to create the “perfect” setting for it in our company, i’m sure it already changed things for the better.

JavaLand 2014 brought also new reasons to play around with the images i’ve collected over ten years now on Daily Fratze. In March i’ve created a JavaFX mosaic generator.

I actually didn’t plan much conferences for 2015 but as i won a ticket to JavaOne in LavaLand: Who am i to let that go to waste?

Stefan Pfeiffer came up in April with the idea of a local JUG (Java User Group), aiming at the Euregio Maas-Rhein. What a great idea! Bert Ertman was our first guest and helped us the get the thing running. I’ve written several recaps about our EuregJUG events, read them here.

Thanks, Stefan. Although it wasn’t too easy between the two of us, I’m gonna miss your input but i know that you’re gonna have a keen eye on the EuregJUG:


2015-07-09_big

In the course of spring i was very proud to be featured with my NetBeans testimonial at Geertjan Wielangas blog at Oracle. Geertjan was also a much appreciated guest at the EuregJUG and provided a lot of his contacts to us so that we have a lot of interesting speakers coming up. Thanks Geertjan, it was a pleasure meeting you, all the times in 2015:


2015-08-25_big

The numbers of visitors at this blog are hard to believe for me. There are an average of ~500 people daily reading articles here. Thanks a lot! I hope they like the new theme i’ve written and installed in August.

Over the year I had so many great conversations on Twitter and via E-Mail with fellow developers from all over the world. For me all those conversations, tweets to articles, different opinions are really valuable and I’ve learned a lot from them, often that really know nothing, or at least not as much as i should. I’m really thankful for that:

Although not able to spell that right 😉

Come October 2015. Thanks to my awesome company ENERKO Informatik i was able to use the JavaOne 2015 ticket i won at JavaLand.

2014 was a lot of first times: First time America, first time JavaOne. JavaOne 2015 was just freaking awesome. I took a week off, flew to Los Angeles instead of San Francisco rented a car and drove to Las Vegas, Grand Canyon, Death Valley, up through the Sierra Nevada and straight through Yosemite Park to San Francisco:

14451707969717903060 14452254218275863085 14453983807893773121 1445226466433913094 14453166371926033103 1445317590185243114 14454000214251593134 14454707616546103143 14454712417139423148 14456430186724243179 14456430187855513183 14456589219351633200

The conference itself was just awesome. Content was great, as last year, but what was different was knowing many people, having dates scheduled and being invited to some parties. Those are just the shots i’ve taken for michael@dailyfratze, but there have been a lot more people i’ve met.

With Mark, Josh and Bruno, Alex and Marcus:
2015-10-25_big 2015-10-26_big 2015-10-27_big

All i can say, the Java community really rocks:


14458788008627263227

My plans for 2016: Keep on learning stuff, work on and with the EuregJUG, go to JavaLand 2016 and maybe one more conference, start teaching myself and my eldest son Scratch and then we’ll see. I’m still convinced i may have something to say in a talk but i’m not quite sure in which direction that should go.

Apart from that: René recently spoke about programmers who have a life separately from a command line interface or an IDE. I have. My life would have been nothing without my wife and family. Thank you, @tinasimons, for always supporting my crazy ideas and enduring my moods when i sleep to little and drink too much in front of the mentioned IDE.

| Comments (0) »

22-Dec-15


Spring 4.2.x, Spring Boot and the Stomp broker relay

If you’re using a StompBrokerRelay on the MessageBrokerRegistry, be careful with your dependencies:

If you’re using Spring Boot 1.2.x, you must have

<dependency>		
    <groupId>org.projectreactor</groupId>		
    <artifactId>reactor-net</artifactId>		
</dependency>

on the classpath, in case of Spring Boot 1.3.x, which depends on Spring 4.2 which depends on Reactor 2, it must be

<dependency>
    <groupId>io.projectreactor</groupId>
    <artifactId>reactor-net</artifactId>        
</dependency>   
<dependency>
    <groupId>io.netty</groupId>
    <artifactId>netty-all</artifactId>
    <version>4.0.31.Final</version>
</dependency>

in addition to org.springframework:spring-messaging respectively org.springframework.boot:spring-boot-starter-websocket otherwise you’ll end with a bunch of missing class exceptions: reactor.io.encoding.Codec in case of 1.2 and reactor.o.codec.Codec in case of 1.3.

I find this pretty inconvenient and i wish the web socket starter would include them.

Edit: Andy was so kind opening an issue for that topic: https://github.com/spring-projects/spring-boot/issues/4522. Stomp Starter would be equally useful.

| Comments (0) »

17-Nov-15


Documenting your API with Spring REST Docs

We’ve been using apiDoc.js in a project for a while. While the resulting documentation looks neat, it has several drawbacks in our Java project.

  • It depends on the full blown NPM stack, doesn’t fit well in a Maven build stack. It can be done via the grunt-maven-plugin and a gruntfile.js, but this is very hard to explain to Java only developer
  • Although the comment syntax looks like JavaDoc comments, it isn’t. And that’s a problem for Java 8 JavaDoc compiler: It fails on most of the “special” terms, so we ended up having several resources files next to our controllers, which contain the documentation. That actually defeats the purpose of apiDoc.js.
  • In the end: We are all lazy developers or at least forgetful, so if an API changes, more often then not, we forget to update the documentation

Enter Spring REST Docs. Franz has been tweeting a lot about it lately and after going 1.0, i definitely wanted to check it out.

The head behind Spring REST Docs is Andy Wilkinson and he has done an outstanding job, helping to document existing APIs or prototypes. The documentation alone should answer nearly every question you might have (it would have answered mine if i just had read it better).

I wish i could write a lengthy blog post how hard it was, to an API documentation to my biking Spring Boot demo project, but i can’t.

I basically followed the instruction to add the corresponding maven plugins in the right order as seen in my pom.xml, added an AsciiDoc template for the documentation and then started using my already existing Spring MVC Tests documentation my api:

The result is already online here: Guide and API of biking.michael-simons.eu, the code above creates this part.

I love the beauty of this concept: Leverage existing tests based on Spring MockMvc to generate a tested API documentation: If you add or remove fields, parameters etc. to or from your API, the test will break. Also, documentation and API are in the right place. The toolchain depends on AsciiDoc, but this can easily run with JRuby, so i need no external tooling for generating my application and provide a Maven (or Gradle) based solution for my developers.

One might say Spring REST Docs cannot be used on a whiteboard project or a project designed using WSDL or other tools, but i disagree: Sketching an API using Spring Boot doesn’t take much time and i can always put classes generated from WSDL into a Boot project, use them as parameters or return values and be good.

So if you’re wondering which tool to use to document your api, you should definitively check out Spring REST Docs.

| Comments (1) »

05-Nov-15