Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

autowire boolean primitive from properties file

Hi I want to autowire boolean value from properties file have referred following link with maps url Spring properties (property-placeholder) autowiring

but I want to auto wire a boolean property, also have referred question Spring Autowire primitive boolean Spring Autowire primitive boolean but that was for bean value and in my case I want to do the same using property value which is dot separated.

${does.it.allow} // which fails and gives String cannot be cast to boolean #{does.it.allow} // this gives no bean/property defined with name does but I have the correct property file and it proves that container is able to load it because of first error.

like image 988
Aniruddha Avatar asked Mar 14 '14 09:03

Aniruddha


1 Answers

It doesn't work for me with primitive boolean. But it does with Boolean type.

This is my spring configuration declaration of the properties file:

<context:property-placeholder location="classpath:path/to/file/configuracion.properties" />

This is what i have in my properties file:

my.property=false

And this is my successful service class:

...
@Service
public class MyServiceImpl implements MyService{
...
    @Value("${my.property}")
    private Boolean nameOfProperty;
...
like image 140
Carlos Avatar answered Sep 20 '22 06:09

Carlos