Spring Boots Configuration Metadata with Kotlin

Last week I decided to raffle a copy of my book (see Twitter) and I wrote a small Spring Boot Command Line Runner to raffle the retweeting winner as one does (see raffle-by-retweet, feel free to reuse this).

I wrote the application in Kotlin. Notice the use of @ConfigurationProperties in my application:

The lateinit attributes are not as nice as I want them to be, but I heard support for data-classes is coming. Anyway. A super useful thing with those configuration property classes are the metadata that can be generated for your IDE of choice, see Configuration Metadata. In a Java application it’s enough to add org.springframework.boot:spring-boot-configuration-processor as compile time dependency respectively as annotationProcessor dependency in a Gradle build.

For Kotlin, you have to use the kotlin-kapt-plugin. It takes care of annotation processing in Kotlin and Spring Boots annotation processor has to be declared in its scope like this:

apply plugin: 'kotlin-kapt'
dependencies {
    // Other dependencies omitted

To make IDEA recognize the generated sources (and also use the same folders for classes as the Gradle build), you can this as well:

apply plugin: 'idea'
idea {
    module {
        def kaptMain = file("${project.buildDir}/generated/source/kapt/main")
        sourceDirs += kaptMain
        generatedSourceDirs += kaptMain
        outputDir file("${project.buildDir}/classes/main")
        testOutputDir file("${project.buildDir}/classes/test")

Find the full build script here.

| Comments (0) »


Cognitive therapy

The featured image on this post is from Cycologygear. I love their shirts and have several of them. Highly recommended products. If you need some new jerseys, go check their shop!

Some days ago, Simon Maple asked the following question on Twitter:

Let me tell you a story. I’m an avid cyclist and run this site for quit a while now. I’m commuting about 20 to 30 kilometers a day now for more than years by bike. Before I had kids, I was into mountain biking. Nowadays more road race. In short: I always considered myself “fit”. Seldom out of breath when going up some stairs etc.

The following picture has been taken in the summer of 2016 and though it was a marvelous moment with my kids on an old boat, I thought: Wow, is that really you? Age 36 back than…

I still felt fine though some shirts and a couple of trousers became a bit small. I ended 2016 with about 85kg (I’m 1.86m tall). In 2017 I did a lot of conferences and user groups, drank a lot of beer and spend my whole spare time in front of a computer writing on my second book and by summer of 2017, it really did show and wasn’t feeling fine at all.

Not only I reached around 88kg, I was perceived ill the whole spring, usually tired and in short: Did not feel good.

I have a history of overdoing things. Being it work, sports, eating and drinking, so I was a bit anxious if buying a Garmin vívosmart® HR+ and a one year subscription of myfitnesspal was a good idea. Especially the later triggered some long forgotten memories with me.

I bought both nevertheless and the result is great. Actually eating more conscious and getting back a feeling what food contains a certain amount of calories was the main win of using myfitnesspal. I configured the app with a target weight of 80kg and a pretty though number of maximum daily calorie intake. I’m a bit stubborn on these kinda things and I wouldn’t recommend it for everybody. Anyway: I reached my goal – starting in July 2017 – by the end of October 2017 and since then, I’m around 79kg, given or take.

The other important aspect for me was doing some stuff I didn’t usually do:

The first running activity in 2017 did hurt. My muscles and my mind: Am I that slow? That soon of of breath? Holy cow… I tracked it with the vívosmart mentioned above. About 4km with a pace of 7:49 min/km. Oh boy.

I kept running and by the end of September I managed reach paces around 6:10 min/km consistently. That’s when things started to hurt less and actually became fun. What doesn’t work for me and probably never will is sports in a gym. Essential for me is actually being outside. Running is considerably easier in autumn and winter than cycling: Not much equipment you have to take care for, just throw everything in to the washing machine and be done with it.

No sports without a battle of equipment and materials. I sold the vívosmart to my friend André and gave myself a nice birthday present, a Garmin fēnix® 5S, a device I could wear the whole day:

You can read about the fēnix 5S for example at DC Rainmaker. For me, it stood up to all it’s promises, especially a battery life for about 7 days with 3 or 4 trainings. I never really wanted a Smart Watch, quit the contrary, I’m a fan of analog watches, but I do like having some notifications on the watch, like text messages from my “favorite” contacts. I do like however the fitness tracker and it’s reminder to get up once in an hour. I’m the kind of person who – when in the flow or really deep done into a problem – doesn’t get up from the chair until problem solved or the bladder ultimately demands its rights, so that improved daily life (work).

I tried to use the sleep tracker, but I don’t like having something around my wrist in my sleep, but I did set the reminder to get into bed before midnight.

I both like Garmin Connect and Garmin Connect Mobile a lot. You’ll need the later on your smartphone to configure your device. Both works as expected. Sometimes the bluetooth connection gets lost but force quitting the app and restarting it helped always on iOS. Both apps offer some good insights. Not sure if they are physically viable but I do like the relative measures. Also, after using the device now for a year, I’m pretty happy with the running result of 725km:


What really baffled me is the step counter, though: I walked nearly 4000km in a year.

I managed to ran 3 half marathons since December 2017, two of them under 2 hours, the third was at the beach and that was… pain 🙂

I’m quite often late to the party. This time for Strava. Many friends tried to convince me to join there but I just did this month. While I keep my Garmin data by myself, I opened my Strava profile and also added some images for my preferred routes. The Garmin Fenix 5S supports Strava live segments and that’s actually a fun way to battle oneself with other athletes for the fastest pace etc.

Anyway. Those numbers aren’t actually that important. I appreciate the measurements because it motivates me to get up and do something, but they are not something that defines me. And the same holds true for (our) passion for work. Reading this post on my IT blog probably means you’re yourself into computer science, programming etc. For whatever reason many of us kinda get sucked into this whole thing and spend more time than it’s healthy with IT. Myself: Not an exception. Shifting some habits did help me a lot, not only being fitter, but focussing more on work in the end.

While being outside and working out helps on clearing ones mind (at least with me), it also helps learning and reading about other things not in our profession. At the moment I am reading the German version of Ken Wilbers Integral Meditation: Mindfulness as a Way to Grow Up, Wake Up, and Show Up in Your Life and it gives me a nice mental shift. Last year I was occupied with the Black Swan by Nassim Taleb for some time.

In the end, it’s a bit of cognitive therapy: After realizing that I have to change habits to change my perception on a lot of things, one thing came to another and nearly 2 years after the first picture in this post has been taken, I feel a lot better and also happier. Not always, but often.

And if that all doesn’t change a bit, maybe just go outside and play ball:

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

| Comments (0) »


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) »


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:

name = Serious Q. Programmer
email = serious.programmer@business.example.com
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) »


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 (3) »