spring-boot icon indicating copy to clipboard operation
spring-boot copied to clipboard

Binding to @ConfigurationProperties on @bean method with a Map does not work

Open hao0111 opened this issue 9 years ago • 1 comments

Hi, i use @ConfigurationProperties on @Bean method, part of code as follow:

@Bean
@ConfigurationProperties("xxx.yyy.aa")
public void dealSomething(){
     DataA a=DataA.create().build();
}

public class DataA(){

public Map<String,String> properties=new HashMap<String,String>();

public static DataA create(){
    return new DataA ();
}

public DataA build(){
  // here, why properties is empty map? It is not set to properties map object
    String url=properties.get("url");  
   MutablePropertyValues values=new MutablePropertyValues(properties);
 //...

   }
}

application.properties

xxx.yyy.aa.url=xxxx
xxx.yyy.aa.user=xxxxx
xxx.yyy.aa.oo=xxx

I want to @ConfigurationProperties on @Bean method with a Map ,it can be work!! please help me,thank you!

hao0111 avatar Jul 04 '17 03:07 hao0111

Thanks for getting in touch, but it feels like this is a question that would be better suited to Stack Overflow. As mentioned in the guidelines for contributing, we prefer to use GitHub issues only for bugs and enhancements. Feel free to update this issue with a link to the re-posted question (so that other people can find it) or add some more details if you feel this is a genuine bug.

wilkinsona avatar Jul 04 '17 05:07 wilkinsona