Want to improve as a dev?

I send a short email every workday about Spring topics, API development and improving as a dev. The current series is about building a Kanban API with Spring.

Basic properties handling - Part 2

15.03.2018 by Jens in Spring Boot | Newsletter

Properties in Spring are not limited to Strings. Sure, they are in the property file, but not necessarily as a field in our class. Whatever type we use, Spring will try to convert the string value from our input to the correct type.

For example with a boolean:

@Value("${myProp}")
private boolean myProp;

We can set the value now like:

myProp=true

Or:

myProp=false

It doesn’t matter what type we use as long as Spring has a converter for it. It covers the most common cases. If not, we can plug in our own, but honestly, I never had the need for that.


comments powered by Disqus