Spring Boot Configuration – Properties not loaded

I had recently a very interesting problem using Spring Boot and the auto magic concerning the configuration.

The Problem

Configuration was not available in my Unit tests but it was working fine in the normal application. I spend a lot of time searching but without real good post concerning this issue.

This code already wasn’t working:

Even if my application.yml / application.properties was looking good:

The solution

Now here the working sample, do you see the difference?

Yes it is just the @SpringApplicationConfiguration instead of the @ContextConfiguration annotation. (Even if the first is itself just a meta annotation of the second.) If you look into this new annotation you will find that it uses a different loader class, which makes the difference.

That’s the trick. Having it in place the Spring Application configuration is successfully parsed an available in your unit test. Doesn’t matter if YAML or just property file.

Paul Sterl has written 20 articles

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">