那个api可以获取spring.cloud.nacos.server-addr
时间: 2024-05-09 12:21:01 浏览: 11
对于Spring Cloud Nacos,可以使用NacosConfigProperties类来获取配置属性,包括spring.cloud.nacos.server-addr。示例代码如下:
```
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.alibaba.nacos.NacosConfigProperties;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class ConfigController {
@Autowired
private NacosConfigProperties nacosConfigProperties;
@GetMapping("/config")
public String getConfig() {
return nacosConfigProperties.getServerAddr();
}
}
```
在这个例子中,@Autowired注解用于自动注入NacosConfigProperties类的实例。然后,可以使用nacosConfigProperties.getServerAddr()方法来获取spring.cloud.nacos.server-addr属性的值。