annotation based Logger injection in Spring with Kotlin

what’s it all about In this post I show how to implement an annotation-based Logger injection in Spring when writing the application with Kotlin. The used technique is quite far from new, basically what I do is implement a BeanPostProcessor which scans the properties of the beans for fields annotated with a custom annotation and sets these fields to a Logger instance. Examples how to implement this in Java can be found on the web, here I show the Kotlin version.

load java logging properties from the classpath

When using plain Java logging the configuration file normally must be set by setting the System property java.util.logging.config.file. There also is the possibility to configure the logging system with a configuration class, but this article deals with file configuration. Using the system property is quite uncomfortable as it involves changing run configurations in the IDE or typing more on the commandline when starting the program. Especially in maven powered builds, where I might wish to have different configurations for test and normal execution this is not an optimal solution.