出于安全目的,我想移动属性文件中的一些配置,但不希望在运行时覆盖它。可以在 Spring Boot 中实现吗?
谢谢, 曼尼什
最佳答案
这样的东西应该可以工作,secure.properties 中的任何内容都将无法被覆盖,因为它将被添加到 env 的开头(从属性文件),无论什么已被覆盖。
@Configuration
public class SecurePropertiesConfig {
@Autowired
public void setConfigurableEnvironment(ConfigurableEnvironment env) {
try {
final Resource resource = new ClassPathResource("secure.properties");
env.getPropertySources().addFirst(new PropertiesPropertySource(resource.getFilename(), PropertiesLoaderUtils.loadProperties(resource)));
} catch (Exception ex) {
throw new RuntimeException(ex.getMessage(), ex);
}
}
}
关于java - 防止覆盖 application.properties 中的某些属性 - Spring Boot,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47039289/