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

后端 未结 6 1184
一向
一向 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:42

    Try this : Make your class a Component

    @Component
    public class UserXXXUtils {
        private static Integer trustXXXMask;
    
        @Value("${trustXXXMask}")
        public void setTrustXXXMask(Integer trustXXXMask) {
            UserXXXUtils.trustXXXMask = trustXXXMask;
        }
        //Access anywhere in the class
    }
    

提交回复
热议问题