如何重新加载弹簧值注释

时间:2020-05-07 13:37:28

标签: spring-boot annotations property-placeholder

我的Spring Boot应用程序中有一个备用application.properties(在外部文件夹中,而不在资源中),该属性是用PropertySourcesPlaceholer定义的:

@Configuration
public class MyApplicationProperties {

    @Bean
    public PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurerAplicaciones() throws IOException {
        PropertySourcesPlaceholderConfigurer properties = new PropertySourcesPlaceholderConfigurer();
        File file = ResourceUtils.getFile(myApplicationLocation());
        properties.setLocation(new FileSystemResource(file));
        properties.setIgnoreResourceNotFound(true);
        return properties;
    }

然后加载类似in的属性

    @Value("${host}")
    private String host;

当我更改属性文件中的值时,Spring不会重新加载其值。

是否有一种方法可以强制加载该属性?

0 个答案:

没有答案