Service register to Nacos
Now, nacos is popular register center,it imp the spring cloud.In this tutorial,I'll step by step register service to nacos.
create namespace
Creating namespaces not only isolates services but also configuration files, allowing these files to be defined in different domains. This facilitates the management of configuration files and helps avoid the issue of different project teams or developers using duplicate names for configuration files.
Maven Dependencies
xml
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
bootstrap.yml
the, we'll configuration the nacos in project bootstrap.yml, also,you should add dependencies
xml
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
edit bootstrap.yml
spring:
application:
name: cloud-mall-system-admin-business # setting you application name
cloud:
nacos:
discovery:
server-addr: 127.0.0.1:8848 # nacos address
username: nacos
password: nacos
namespace: 8bde195d-0b0d-4c67-9890-0f2c71594581 # namespace id, you call get it it from nacos web page
group: MALL_GROUP # define group
service: ${spring.application.name} # servicename
add @@EnableDiscoveryClient annotation
java
@SpringBootApplication
@EnableDiscoveryClient
public class SystemAdminApplication {
public static void main(String[] args) {
SpringApplication.run(SystemAdminApplication.class,args);
}
}
run
when start you project, you can find service has register to nacos.see below: