Nacos教程_4 配置讲解
教程原稿 https://gitee.com/fakerlove/joker-nacos
文章目录
- 配置讲解
- 4.1 dataid 配置讲解
- 4.2 实现自动装填
4. 配置讲解
4.1 dataid 配置讲解
在 Nacos Spring Cloud 中,dataId
的完整格式如下:
${prefix}-${spring.profiles.active}.${file-extension}
prefix
默认为spring.application.name
的值,也可以通过配置项spring.cloud.nacos.config.prefix
来配置。spring.profiles.active
即为当前环境对应的 profile,详情可以参考 Spring Boot文档。 注意:当spring.profiles.active
为空时,对应的连接符-
也将不存在,dataId 的拼接格式变成${prefix}.${file-extension}
file-exetension
为配置内容的数据格式,可以通过配置项spring.cloud.nacos.config.file-extension
来配置。目前只支持properties
和yaml
类型。
4.2 实现自动装填
package cn.com.geostar.datasource;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Component;
/**
* @author xiawei
* @date 2020/8/10 11:33
*/
@Component
@RefreshScope
@ConfigurationProperties(prefix = "jedispool.config")
public class JedisPoolConfigure {
private boolean enable;
private String host;
private Integer port;
private String password;
private Integer timeOut;
private Integer maxIdle;
private Integer maxWaitMillis;
private Integer maxTotal;
}
还没有评论,来说两句吧...