1

I'm facing following problem with @ConfigurationProperties placed on @Bean.The configuration is placed into application.yml within the library jar by default:

@Configuration
@ConfigurationPropertiesScan
public class MyConfiguration {

    @ConfigurationProperties("myprefix")
    @Bean
    public MyConfigProperties configProperties(){
       return new MyConfigProperties();
    }
}

MyConfigProperties.java - simple pojo

public class MyConfigProperties {
   private String myproperty;

public String getMyproperty( ...
public void setMyproperty( ...
} 

application.yml

myprefix:
   myproperty: defaultValue

From the @SpringBootTest in the same project it works just fine. But if I use the library from another project, I always need to provide the myprefix.myproperty even the defaulValue would work fine for me.

My expectation is, the defaultValue should be taken from the application.yml provided within the jar, if no properties with higher precedence given.

Am I doing something wrong?

Kind regards,

Gena

Gena Batalski
  • 103
  • 1
  • 2
  • 6
  • check my answer here. It might help https://stackoverflow.com/questions/60935878/how-to-specify-the-default-value-for-nested-property/60939255?noredirect=1#comment107821031_60939255 – pvpkiran Mar 31 '20 at 08:49
  • Hi and thank you for the hint! But i think, this is suspect to use `@PostConstruct` or `@DefaultValue` for such usecase. It did work just fine with `@Value` and i mean, it should work with `@ConfigurationProperties` as well. The consern is to provide default application.yml/application.properties within the jar containing eg. evaluation license or other meaningful defaults. – Gena Batalski Mar 31 '20 at 10:16
  • @GenaBatalski, have you tried @ConfigurationProperties(prefix="myprefix") ? –  Apr 01 '20 at 09:12

0 Answers0