spring cloud nacos 平台搭建——服务注册
官方demo:https://github.com/nacos-group/nacos-examples
注意版本对应 版本说明 Wiki
spring cloud nacos 平台搭建——nacso注册中心搭建: https://www.cnblogs.com/cyh1282656849/p/14128189.html
项目结构
<!-- 基础服务 -->
<module>base</module>
<!-- 公共模块 -->
<module>common</module>
<!-- 注册中心管理 -->
<module>nacos-manage</module>
<!-- 网关 -->
<module>gateway</module>
根pom配置
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.3.2.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>indi.cyh.platform</groupId> <artifactId>parent</artifactId> <version>0.1</version> <packaging>pom</packaging> <modules> <!-- 基础服务 --> <module>base</module> <!-- 公共模块 --> <module>common</module> <!-- 注册中心管理 --> <module>nacos-manage</module> <!-- 网关 --> <module>gateway</module> </modules> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> <spring-cloud.version>Hoxton.SR8</spring-cloud.version> <spring-cloud-alibaba.version>2.2.3.RELEASE</spring-cloud-alibaba.version> </properties> <dependencyManagement> <dependencies> <!--spring-cloud依赖--> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>${spring-cloud.version}</version> <type>pom</type> <scope>import</scope> </dependency> <!--spring-cloud依赖--> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-alibaba-dependencies</artifactId> <version>${spring-cloud-alibaba.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <dependencies> </dependencies> <build> <defaultGoal>compile</defaultGoal> </build> </project>
注册服务pom
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>indi.cyh.platform</groupId> <artifactId>parent</artifactId> <version>0.1</version> </parent> <artifactId>base</artifactId> <name>base</name> <description>基础服务</description> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> <version>${spring-cloud-alibaba.version}</version> </dependency> <!--lombok插件--> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.16</version> </dependency> <dependency> <groupId>indi.cyh.platform.common</groupId> <artifactId>log</artifactId> <version>0.1</version> </dependency> <dependency> <groupId>indi.cyh.platform.common</groupId> <artifactId>db</artifactId> <version>0.1</version> </dependency> </dependencies> </project>
启动类
@SpringBootApplication @EnableDiscoveryClient public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } }
bootstrap.yml配置文件
server: port: 800 spring: application: name: base-provider cloud: nacos: discovery: server-addr: 127.0.0.1:8888 group: base-service
启动成功后注册中心可见