nacos 动态刷新@ConfigurationProperties

使用@ConfigurationProperties 能够替换@valuejava

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

 

nacos 配置文件yaml中添加spring

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

添加pom.xmloracle

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

config.javaspring-boot

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; }
相关文章
相关标签/搜索