how to pass values dynamically in config file

后端 未结 2 1238
夕颜
夕颜 2020-12-20 10:17

I want to pass the value in the value tag of the property dynamically from the DB. Is this possible in Spring? And how ?

For example in the configuration below.

2条回答
  •  感动是毒
    2020-12-20 10:38

    You can write a another Java class and make it as a bean in Application context and using Spring Expression Language, you have evaluate and get output of the method call.

    XML configuration:

    
    
    

    WeServiceInfoFromDB.java class:

    class WebServiceInfoFromDB {
    
       public String getWsdlUrl() {
          // Get the Wsdl URL from DB.
          return wsdlUrl;
       }
    
       public String getUsername(){
          // get the username from DB
          return username;
       }
    

    XML configuration in application context:

    
       
    
    

提交回复
热议问题