biking2: Four years later

I have written a book about Spring Boot 2, taught Spring Boot 2 at customer but haven’t had time yet to update biking.michael-simons.eu to use Spring Boot 2.

That project is – in it’s current Spring based incarnation – with me since the first early access releases of Java 8 and the first betas and release candidates of Spring Boot (for example, see that post).

I started the migration in a separate branch in the public repository while I was tracking the massive amount of changes in Boot in the last quarter of 2017 for my book.

Today, I finished it. The branch has been deleted, but I kept the most relevant commits and prefixed those that I think are important with Boot2. I rearranged and squashed a lot of the commits, I don’t expect the single commits to compile. The latest commit however does.

I personally found the changes in security a bit though to tackle but worth the effort. Also, if one relies on the Actuator Metrics endpoint, there’ll be some tasks ahead. The migration was in over-all quit smooth and pleasant.

The one thing that bit me though was the fact that I start the application with -Dspring.config.location=conf/application.properties. In Spring Boot prior to 2 this adds the given location to the configuration. With Spring Boot 2 this replaces config location. I have this in my book, so I really think I’m getting old. The correct way in Spring Boot 2 to add additional config location is -Dspring.config.additional-location=conf/application.properties.

In the process of upgrading I also upgraded and tested my wro4j-spring-boot-starter. Since 0.4.x it’s fully supported on Boot 2. I will not maintain the older branches until necessary. At the moment, wro4j seems a bit dormant anyway.

Anyway: A big thank you to all the people in the Spring Team and other contributors for answering my questions, discussion issues with me, providing great software and in general for being really kind and welcoming.

| Comments (0) »

27-Jun-18


Use different Git usernames and emails for work and play

A bit hidden away in the release notes of Git 2.13 but found by my friend Michael Vitz from INNOQ is the not so new anymore feature of conditional configuration respectively conditional includes.

Git has several levels of configuration: System wide, per user, per repository and finally, on each individual command invocation. If a values is defined on several levels, the most specific counts.

Configuration files can include other files with include and includeIf. The included files behave as if the configuration they contain had been written in the including file.

includeIf includes files conditionally. Right now, it only supports one attribute, gitdir: “The data that follows the keyword gitdir: is used as a glob pattern. If the location of the .git directory matches the pattern, the include condition is met.”

Depending on the directory your repo is in, you can pull in different configuration files. That comes in very handy to configure different a different username and email address, for example to differentiate between work and play (taken directly from the release notes):

Put this into your user specific .gitconfig:

[includeIf "gitdir:~/work/"]
  path = .gitconfig-work
[includeIf "gitdir:~/play/"]
  path = .gitconfig-play

And create additional .gitconfig-work and .gitconfig-play (the files can reside wherever you want, you can use a full path as well:

[user]
name = Serious Q. Programmer
email = serious.programmer@business.example.com
[user]
name = Random J. Hacker
email = rmsfan1979@example.com

Read more about git-config includes and fine more usage examples in the official documentation. I curate a list of some more or less useful git snippets here.

Did you like this article? You can invite me on a coffee ☕️ if you like.

| Comments (0) »

25-Jun-18


Maven: Use JUnit 5 with Spring Boot for unit and integration tests

Last weekend, a new version of the Apache Maven Surefire-Plugin has been released:

The Failsafe-Plugin has been updated as well. Both support JUnit 5 natively.

To make use of JUnit 5 in a Spring Boot 2 application, there’s not much todo. Here’s a gist of a POM that brings everything. See comments in the code. Basically all you have to do is overwrite the managed versions of the Surefire- and Failsafe-Plugins and then exclude the JUnit 4 dependency from Spring Boots Starter Test (and all other test related starters, i.e. security-starter-test). You’ll than declare both the JUnit 5 Jupiter Api and Engine, both in scope test. You could put the engine into the plugins dependency, but I couldn’t think of an aspect that’s improved by more cruft. Then, write unit and integration tests as shown (the later with annotated with @ExtendWith(SpringExtension.class)).

You’ll notice that only the Failsafe-Plugin has been declared. Spring Boots parent POM already takes care of the Surefire-Plugin.

And that’s all you need for Spring Boot 2 with JUnit 5.

Did you like this article? You can invite me on a coffee ☕️ if you like.

| Comments (5) »

18-Jun-18


Some thoughts about Effective Java, Third Edition and general musings

Lately, German publisher dpunkt.verlag reached out to me wether I’d think it’s a good idea translating Joshua Blochs Effective Java 3rd edition (Partnerlink) to German. Effective Java has been on my Good reads list for a while now and I read the first edition in 2003 or 2004, don’t remember exactly when. I hopefully learned a thing or two in that time and sadly seen some things better left unseen and my initial thought was: Go for it! If a translated version helps spreading best practices and especially things one should not do, it’s worth the effort.

To my surprise, dpunkt than asked if I could review the translation. And so it happened that I read the third edition in its total, mostly parallel in German and English:

My friend Thorben has reviewed the book already very concise at his Thoughts on Java blog. I fully agree with him.

One thing I have to quote is Joshua Bloch himself:

If you have ever studied a second language yourself and then tried to use it outside the classroom, you know that there are three things you must master: how the language is structured (grammar), how to name things you want to talk about (vocabulary), and the customary and effective ways to say everyday things (usage). Too often only the first two are covered in the classroom, and you find native speakers constantly suppressing their laughter as you try to make yourself understood.

This is from the foreword itself and is basically the essence of the book.

If one gets the idea on how to start a Java program, the weird notion of the main-method and have an idea about objects, Java does not have a step learning curve. One can solve many problems without going deeper into the specifications or fully understanding what’s happening behind the scenes.

Most of the time, stuff works out, some times not. Usually those times happen to be late in the evening, on a weekend duty etc. Performance optimizations that should not have been done. Cloneable or serializable classes that violates their invariants. And many more.

Effective Java does address all these and more.

It also is written from an API creators point of view as one clearly sees on how Joshua stresses good documentation at the API level.

One does wonder if qualities being important for an API are equally important for a product or a software that has it’s value in the business it powers? I’d say yes. There’s always a team that has to maintain code or hast to fix bugs. Add new features. I don’t believe in a permanent rewrite of (micro)services. By all probability, the Netflixes, Amazons and Googles of this world do this, but at least I have not yet been in a project where that was a legitimate thing.

Given that premise, I’d rather build my stuff on a solid fundament and that starts with some best practices and at least the ambition to learn a language a bit deeper than just on the surface.

Funny enough, my tweet about Lombok did gain some traction:

I like the project but use it very selectively, most of the time @Getter, @Setter, @EqualsAndHashCode (that one only with the of-attribute) and sometimes @Builder. I use it to create immutable, small values classes with not more than 4 or 5 fields and @RequiredArgsContructor. I’m probably even the last person who learned yesterday, that there is @Synchronized, but at least I can explain what and why the stuff that @Synchronized does, is actually a good idea. If one has a library like Lombok or Googles AutoValue in a project, an understanding of Javas details become paramount or otherwise all kinds of interesting things can happen (if we speak on a higher level like Michael @bitboss Plöd argues, inflationary generation of accessors defies information hiding and encapsulation and should be avoided).

If you want to master the language Java, read all items in the book. If you’re more into other (JVM) languages as well, the chapters General programming, Exceptions and Concurrency have value without Java, too (By the way, you should sometimes have a look at other languages. Kotlin is nice and Simon has a great blog. However it might be a good idea to really look outside the OO box and take a sneak peek at Clojure).

tl;dr: I firmly believe that one has not to master every detail of a day-to-day language but one should know more than just the basics and to the right things the right way. Effective Java has some more or less controversial items, but overall, it indeed helps to be more effective.

| Comments (0) »

08-Jun-18


May 2018: Interviews, Spring I/O and more

Hard to believe, May is already gone. The month was pretty though for me, it startet with a bike crash for me, that cost me a bike and some time at the doctors.

Interviews and articles

I was very happy about publications at Heise Developer. First of all there has been a recap about JavaLand 2018 and the mentoring program in which I took part: Die jungen Wilden pt. 2.

Next was an interview conducted by Thorben Janssen with me, also for Heise Developer: Im Gespräch: Michael Simons über Spring Boot 2 und sein neues Buch. Thanks a lot for that, Thorben!

There was another interview I did during JAX last month with the JAXenter: Michael Simons über Softwarearchitektur. My series of articles about Spring Boot 2 has been translated to English for the international version of JAXenter as well: part 1, part 2, part 3 and part 4.

And last but not least, I wrote a piece for Informatik Aktuell about 4 years of Spring Boot: 4 Jahre Spring Boot.

My book is available on Amazon, as paperback and Kindle-Edition.

Spring I/O 2018

I did travel a lot in May, some holiday, but also work. I was at Spring I/O again, this time with a session about Micrometer:

Micrometer and metrics are a super interesting topic. I put a lot of effort into this talk and into the demo. To my personal disappointment, I delivered the talk not as good as I wished. The month with it’s bad start and the traveling took a bigger toll on me than expected. Anyway. I tried something new and published my personal transcribed for the talk as well, find it here. The sources for the demo are – as always – on GitHub.

| Comments (0) »

28-May-18