java - Spring 在运行时更改属性文件

标签 java spring spring-boot properties-file

我正在使用 Spring Boot,我有一个属性文件 p.properties:

p1 = some val1
p2 = some val2

配置类:

@Configuration
@PropertySource("classpath:p.properties")
public class myProperties {

    public myProperties () {
        super();
    }

    @Bean
    public static PropertySourcesPlaceholderConfigurer placeholderConfigurer() {
        return new PropertySourcesPlaceholderConfigurer();
    }
}

我正在使用它来访问该属性:

@Value("${p1}")
private String mProperty;

一切正常。 我想从应用程序外部更改 p.properties 文件中的 p1,下次我将使用 mProperty 时,它将包含新值而无需重新启动应用程序。 可能吗?

谢谢, 视频

最佳答案

您可以简单地使用spring boot actuator。 只需在您的 maven/gradle 配置 中添加执行器依赖项,当您更新 property 文件时,您应该会看到实时重新加载。

注意:您不必重新启动应用程序,但执行器会自行执行实时重新加载

关于java - Spring 在运行时更改属性文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49977392/

相关文章:

java - 信号量 : Permit acquired in one thread can be released from another thread - Example

java - 如何通过电子邮件通过撇号进行验证并使用正则表达式限制 @ 符号后的点数。 (JAVA)

java - 如何更新 Spring WebFlow 模型中的数据并将其传递回同一 View

java - Hibernate-Spring boot : spring. jpa.hibernate.ddl-auto=update 更新实体后重新创建表和列

spring - 自定义 Spring 条件导致 java.lang.NoSuchMethodException : <init>() exception

java - spring security Remember Me logut 不清除 cookie

java - Spring hibernate ,事务提交或事务回滚后如何调用某些方法

java - 为消费者和生产者创建休息端点

java - 为什么 request.getRemoteAddr() 根据上下文返回 ipv4 或 ipv6(post 查询或 ajax 查询)

java - Spring Boot应用程序不使用jemalloc