1.先在服务器上安装jdk1.8和maven3.2.x+ 2.https://github.com/alibaba/nacos/releases下载安装包 tar -zxvf nacos-server-1.2.0.tar.gz cd nacos/bin 程序启动默认占用的端口是8848,可以在conf文件下的application.properties中修改 server.port=9090 启动命令(standalone代表着单机模式运行,非集群模式): sh startup.sh -m standalone localhost:9090/nacos访问控制台 3.新建服务端注册到nacos上 @EnableDiscoveryClient public class MyApplication { public static void main(String[] args) { SpringApplication.run(MyApplication.class, args); } } <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.5.RELEASE</version> <relativePath/> </parent> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>Greenwich.RELEASE</version> <type>pom</type> <scope>import</scope> </dependency> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> <version>2.1.1.RELEASE</version> </dependency> spring: application: name: order cloud: nacos: discovery: server-addr: 127.0.0.1:9090 一开始项目打war包放tomcat上跑,会注册不了服务,后来换成用jar启动方式就能注册成功了。若一定要放tomcat上跑,网上有解决方案。 新建了2个服务端,都注册到nacos上,然后一个服务用FeignClient调用另一个服务,添加以下依赖 <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-openfeign</artifactId> <version>2.1.1.RELEASE</version> </dependency> 但在调用过程中,发生以下报错 java.lang.ClassNotFoundException: com.netflix.config.CachedDynamicIntProperty 网上查了下解决方案,加上以下依赖即可: <dependency> <groupId>com.netflix.archaius</groupId> <artifactId>archaius-core</artifactId> <version>0.7.6</version> <exclusions> <exclusion> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> </exclusion> </exclusions> </dependency> 4.相关官方链接: https://github.com/alibaba/spring-cloud-alibaba/wiki/%E7%89%88%E6%9C%AC%E8%AF%B4%E6%98%8E https://github.com/alibaba/spring-cloud-alibaba/wiki/Nacos-discovery https://nacos.io/zh-cn/docs/quick-start.html
nacos安装与使用
最新推荐文章于 2024-07-11 20:43:30 发布