Search code examples
javaspring-bootdynamic-properties

can I convert String to Boolean in @ComponentScan::lazyInit?


In application.properties:

app.lazy_init=true

and in Main class :

@ComponentScan(lazyInit = "${app.lazy_init: false}")
public class Main(){...}

But the lazyInit is a Boolean, how can I convert a String to a Boolean in @ComponentScan::lazyInit?


Solution

  • You can't. lazyInit is typed as a boolean so the value that you configure it with has to be a boolean at compile time. In other words, there's no opportunity for converting the String to a boolean as that conversion has to be performed at runtime.