import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import javax.annotation.PostConstruct; @Component public class Constants { @Value("${com.password}") private String password; public static String PASSWORD; @PostConstruct public void init() { PASSWORD = password; } }
本文展示了一个使用Spring框架通过@Value注解从配置文件读取属性并将其赋值给静态变量的例子。此方法适用于需要在整个应用中共享的配置参数。
3520

被折叠的 条评论
为什么被折叠?



