Bläddra i källkod

feat:完成Eureka服务注册中心搭建

yang yi 1 år sedan
förälder
incheckning
c9e50faae3

+ 2 - 0
.gitignore

@@ -50,6 +50,8 @@
 !*.kt
 !*.kts
 
+!.gitignore
 !/common
 !/member-service-provider_10000
 !/member-service-consumer
+!/eureka-server_9001

+ 29 - 0
eureka-server_9001/pom.xml

@@ -0,0 +1,29 @@
+<?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">
+    <parent>
+        <artifactId>distributedSystemLearn</artifactId>
+        <groupId>anyi.space</groupId>
+        <version>1.0-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>eureka-server_9001</artifactId>
+
+    <properties>
+        <maven.compiler.source>17</maven.compiler.source>
+        <maven.compiler.target>17</maven.compiler.target>
+    </properties>
+    <dependencies>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-web</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
+        </dependency>
+    </dependencies>
+
+</project>

+ 20 - 0
eureka-server_9001/src/main/java/anyi/space/eurekaServer/EurekaServerApplication.java

@@ -0,0 +1,20 @@
+package anyi.space.eurekaServer;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
+
+/**
+ * @ProjectName: distributedSystemLearn
+ * @FileName: EurekaServerApplication
+ * @Author: 杨逸
+ * @Data:2025/4/14 19:11
+ * @Description:
+ */
+@EnableEurekaServer
+@SpringBootApplication
+public class EurekaServerApplication {
+    public static void main(String[] args) {
+        SpringApplication.run(EurekaServerApplication.class, args);
+    }
+}

+ 18 - 0
eureka-server_9001/src/main/resources/application.yaml

@@ -0,0 +1,18 @@
+server:
+  port: 9001
+spring:
+  application:
+    name: eureka-server
+
+eureka:
+  instance:
+#Eureka服务端的实例名称
+    hostname: localhost
+  client:
+#配置不向服务中注册自己
+    register-with-eureka: false
+#配置不向服务中抓取注册信息,因为自己就是服务端
+    fetch-registry: false
+#配置服务注册中心的地址
+    service-url:
+      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka

+ 12 - 0
pom.xml

@@ -11,10 +11,12 @@
         <module>member-service-provider_10000</module>
         <module>member-service-consumer</module>
         <module>common</module>
+        <module>eureka-server_9001</module>
     </modules>
     <packaging>pom</packaging>
 
     <properties>
+        <!--指定各种版本的依赖-->
         <maven.compiler.source>17</maven.compiler.source>
         <maven.compiler.target>17</maven.compiler.target>
         <spring.boot.version>2.7.17</spring.boot.version>
@@ -22,10 +24,12 @@
         <log4j.version>1.2.17</log4j.version>
         <mybatis.plus.version>3.4.3.4</mybatis.plus.version>
         <druid.version>1.2.16</druid.version>
+        <spring.colud.version>2021.0.6</spring.colud.version>
     </properties>
 
     <dependencyManagement>
         <dependencies>
+            <!--springBoot父项目的依赖,以pom配置文件的形式导入-->
             <dependency>
                 <groupId>org.springframework.boot</groupId>
                 <artifactId>spring-boot-starter-parent</artifactId>
@@ -33,6 +37,14 @@
                 <type>pom</type>
                 <scope>import</scope>
             </dependency>
+            <!--springCloud父项目的依赖,以pom配置文件的形式导入-->
+            <dependency>
+                <groupId>org.springframework.cloud</groupId>
+                <artifactId>spring-cloud-dependencies</artifactId>
+                <version>${spring.colud.version}</version>
+                <type>pom</type>
+                <scope>import</scope>
+            </dependency>
             <dependency>
                 <groupId>com.mysql</groupId>
                 <artifactId>mysql-connector-j</artifactId>