最近搭建spring alibaba cloud,出现的问题以及解决方式
1.搭建nacos-server,下载地址Releases · alibaba/nacos · GitHub
2.安装需要注意jdk版本,以及环境变量的设置
我的电脑-》属性-》高级系统设置-》环境变量
A.新增JAVA_HOME 例如D:\Java\jdk-18.0.2.1
B.增加path路径例如%JAVA_HOME%\bin
3.安装mysql数据库
下载地址:MySQL :: Download MySQL Community Server (Archived Versions)
具体可以参考MySQL下载安装使用-完整详细步骤_weixin_39450145的博客-CSDN博客_mysql的下载安装步骤
4.创建spring alibaba cloud nacos client
A.pom.xml
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>com.XXX</groupId> <artifactId>XXX</artifactId> <version>0.0.1-SNAPSHOT</version> </parent> <groupId>com.XXX</groupId> <artifactId>XXX-nacos</artifactId> <version>0.0.1-SNAPSHOT</version> <name>mscode-nacos</name> <description>mscode-nacos</description> <properties> <java.version>11</java.version> </properties> <dependencies> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> </dependency> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId> </dependency> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-jcl</artifactId> <version>2.12.0</version> <scope>runtime</scope> </dependency> <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> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
B.XXXNacosApplication
import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
@SpringBootApplication
@EnableDiscoveryClient
public class XXXNacosApplication{ public static void main(String[] args) { SpringApplication.run(XXXNacosApplication.class, args); } }
注意:1.项目启动之后链接nacossever失败,这个时候我添加了
2.链接还是失败,根据资料查询,判断是版本冲突了
版本对应关系:版本说明 · alibaba/spring-cloud-alibaba Wiki · GitHub
3.应用服务就可以注册成功了
4.但是http://192.168.2.147:8848/nacos/index.html 不显示注册服务,
添加了
此时,正确显示注册服务
下一篇说明一下nacosconfig