dubbo x nocas 外部化配置
增加POM依赖
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
配置文件
bootstrap.properties
spring.application.name=dubbo-consumer-config
spring.cloud.nacos.config.server-addr=184.172.234.118:30848
spring.cloud.nacos.config.file-extension=yaml
增加注解@RefreshScope
可以实时刷新配置
package ml.yompc.apache.dubbo.consumer.controller;
import ml.yompc.apache.dubbo.provider.api.EchoService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
/**
* @email yom535@outlook.com
* @author: 有民(yom535)
* @date: 2019/8/18
* @time: 2:03
*/
@RefreshScope
@RestController
public class EchoController {
@Reference(version = "1.0.0")
private EchoService echoService;
@Value("${user.name}")
String name;
@GetMapping(value = "/echo/{echo}")
public String echo (@PathVariable String echo){
return echoService.echo(echo+name);
}
}