0

I have a dependency jar which has values configured in yaml as below:

app:
  settings:
    value1 : true

And the java code is

public class LoadConfig {

    @Value("${app.settings.value1}")
    private Boolean value1;
}

While deploying the spring boot app, in runtime, the dependency jar values are not parsed and below issue occurred.

org.springframework.beans.factory.UnsatisfiedDependencyException: 
    Error creating bean with name 'LoadConfig':
    Unsatisfied dependency expressed through field 'value1'; nested exception is 
    org.springframework.beans.TypeMismatchException:**Failed to convert value of type 'java.lang.String' to required type 'java.lang.Boolean'**; nested 
    exception is java.lang.IllegalArgumentException: Invalid boolean value [**${app.settings.value1}**].

The issue is instead of value, path(app.settings.value1) is getting converted to Boolean and the error is thrown.

maven project structure is

MyJar --> app.jar
    |-> dependency.jar 
Arunkumar
  • 11
  • 5

4 Answers4

0

Base on this you can try:

@Value("#{new Boolean('${app.settings.value1}')}")
private Boolean value1; 

But the real problem is here: exception is java.lang.IllegalArgumentException: Invalid boolean value [**${app.settings.value1}**]. It pass not the value but the label, that cannot be parsed as boolean.

lczapski
  • 4,026
  • 3
  • 16
  • 32
-1

Please try this code:

@Value("${app.settings.value1}")
private Boolean value1;
Alexander van Oostenrijk
  • 4,644
  • 3
  • 23
  • 37
-1

Also it can be primitive:

@Value("${app.settings.value1:false}")
private boolean value1;
Dmitry Ionash
  • 763
  • 5
  • 11
-1

You can try the following ways:

//If you need a Boolean object
@Value("#{new Boolean('${app.settings.value1}")
private Boolean value1; 

OR

//If you need a primitive boolean
@Value("${app.settings.value1:true}")
private boolean value1; 

Please check boolean values in Spring application.properties file?

Raveesh Sharma
  • 1,486
  • 5
  • 21
  • 38