nacos 动态刷新@ConfigurationProperties


使用@ConfigurationProperties 可以替换@value

  @ConfigurationProperties @Value
注解功能 可以批量注入配置文件中的属性 只能一个个指定注入属性
松散语法绑定(Relaxed binding) 支持 不支持
EL表达式 不支持 支持
JSR303数据校验 @Validated 支持 不支持
复杂类型封装 支持 不支持

 

nacos 配置文件yaml中添加

cases:
  ftpPath: "" #http://143.82.3.199:8080/dossier/doc?wjlj=
  prefix: "" #"TYYW."
  dbLinks: "" #"@tyywsc.net"
  isTiming: 1 #是否开启定时任务(1:开启;0:不开启)

添加pom.xml

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-configuration-processor</artifactId>
    <optional>true</optional>
</dependency>

config.java

package com.zjjw.sync.service.config;

import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

/**
 * @author tongzuqi
 * @date: 2019/9/19 8:59 PM
 */
@Getter
@Setter
@Component
@ConfigurationProperties(prefix = "cases")
public class RefreshConfig {

    /**
     * 是否开启定时任务
     */
    private Integer  isTiming;

    /**
     * oracle表用户
     */
    private String  prefix;

    /**
     * oracle令牌
     */
    private String  dbLinks;
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM