1.官网下载
Nacos官网| Nacos 配置中心 | Nacos 下载| Nacos 官方社区 | Nacos 官网,找到对应的版本下载
2.下载完成解压
3.在bin输入cmd
然后输入startup.cmd -m standalone启动,如果直接点击startup,会打不开,因为是默认集群模式,standalone是单机模式,集群是cluster,成功
也可以修改这个startup.cmd
4.默认端口为8848。访问地址:http://127.0.0.1:8848/nacos
5.使用
1.导入依赖
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>2.2.5.RELEASE</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
2.在启动类上添加
@SpringBootApplication
@EnableDiscoveryClient
public class OrderAppliaction {
@Bean
@LoadBalanced
public RestTemplate create() {
return new RestTemplate();
}
public static void main(String[] args) {
SpringApplication.run(OrderAppliaction.class);
}
}
6.配置文件添加
spring:
cloud:
nacos:
discovery:
service: order-serv
server-addr: localhost:8848