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