地址
https://github.com/alibaba/nacos/releases
拉到下面找到这里,下载安装
启动命令(standalone代表着单机模式运行,非集群模式):
sh startup.sh -m standalone
如果您使用的是ubuntu系统,或者运行脚本报错提示[[符号找不到,可尝试如下运行:
bash startup.sh -m standalone
启动命令(standalone代表着单机模式运行,非集群模式):
startup.cmd -m standalone
至此nacos可以正常启动,
账号密码均为:nacos
bootstrap.yml配置
spring: application: name: com.ebiz.han.user//对应Data ID cloud: nacos: config: server-addr: 127.0.0.1:8848 file-extension: yaml//对应nacos配置的后缀
注意暂时只支持yaml和properties格式
在创建springcloud项目时,最需要注意的问题就是版本对应的问题,请仔细看如下:
Data ID
依赖
<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId> <version>2.2.1.RELEASE</version> </dependency> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> <version>2.2.1.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <!-- <dependency>--> <!-- <groupId>com.ebiz</groupId>--> <!-- <artifactId>spring_cloud_provider_client</artifactId>--> <!-- <version>0.0.1-SNAPSHOT</version>--> <!-- </dependency>--> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-openfeign</artifactId> <version>2.2.4.RELEASE</version> </dependency> </dependencies>
server-addr :nacos地址, 127.0.0.1等价于localhost, 主机地址
、
ConfigController
package com.ebiz.nacos.controller;
?
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
?
@RestController
@RequestMapping("/config")
@RefreshScope
public class ConfigController {
?
@Value("${user:false}")
private String user;
?
@RequestMapping(value = "/get",method = RequestMethod.GET)
public String get(){
return user;
}
}
请求成功
这里我用的postman软件,感兴趣可以去下载!
springcloud Nacos2.0.3配置连接IDEA一篇搞定
原文:https://www.cnblogs.com/love-Hy/p/15089277.html