一:nacos端
1.官方下载 nacos 1.3.2
2.下载好后,修改配置文件 E:\tools\nacos\conf\application.properties
3.将数据库导入到mysql中
E:\tools\nacos\conf\nacos-mysql.sql
4.复制文件,修改ip
复制 E:\tools\nacos\conf\cluster.conf.example 修改为 E:\tools\nacos\conf\cluster.conf
然后将配置文件中的ip地址修改为自己的就ok了
5.最后启动 startup.cmd
6.访问 http://192.168.0.109:8848/nacos 默认密码和用户名都是 nacos
7.新建配置配置信息:
二:springboot端
1.引入nacos依赖
<!-- nacos 依赖 -->
<dependency>
<groupId>com.alibaba.boot</groupId>
<artifactId>nacos-config-spring-boot-starter</artifactId>
<version>0.2.1</version>
</dependency>
<dependency>
<groupId>com.alibaba.boot</groupId>
<artifactId>nacos-config-spring-boot-actuator</artifactId>
<version>0.2.1</version>
</dependency>
2.配置application.java
@NacosPropertySource(dataId = "api",groupId="erlang", autoRefreshed = true)
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Bean
public RequestContextListener requestContextListener(){
return new RequestContextListener();
}
3.application.yml配置nacos连接地址
nacos:
config:
server-addr: 127.0.0.1:8848
4.测试类
@NacosValue(value = "${erlang.testvalue:123}", autoRefreshed = true)
private String testvalue;
@ApiOperation(value = "读取nacos配置文件信息")
@GetMapping("readApplication")
public Object readApplication() {
return Result.success(testvalue);
}
5.请求结果
三:
浮生若梦,共勉之