spring - read property value from properties file in static field of class

后端 未结 6 1122
一向
一向 2021-02-06 12:07

I have one utility class where i have one method which requires username and password to connect other url. I need to kept that username in properties file so that i can change

6条回答
  •  青春惊慌失措
    2021-02-06 12:36

    In you Utility class you can have a setter method to set the properties and then you can use MethdInvokingFactoryBean.

    class Utility{
        static String username;
        static String password;
        public static setUserNameAndPassword(String username, String password){
            Utility.username = username;
            Utility.password = password;
        }
        //other stuff
    }
    
    
        
            
                classpath*:/myservice_detaults.properties
                classpath*:/log4j.properties
            
        
    
    
    
        
        
            
                ${username}
                ${password}
            
       
    
    

提交回复
热议问题