Spring Eureka的使用入门

Eureka调度服务:

   Gradle依赖包:

基础框架依赖配置核心代码:

复制代码
    buildscript {
        repositories {
            mavenCentral()
        }
        dependencies {classpath 'org.springframework.boot:spring-boot-gradle-plugin:1.5.14.RELEASE' }
    }
    
    afterEvaluate {Project  project -> 
        if (project.pluginManager.hasPlugin('java')) {
            configurations.all {
                resolutionStrategy.eachDependency {DependencyResolveDetails details -> 
                    forceVersion details, 'org.springframework.boot', '1.5.14.RELEASE'
                    forceVersion details, 'org.springframework.cloud:spring-cloud-dependencies', 'Edgware.SR4'
                    forceVersion details, 'org.slf4j', '1.7.21'
                }
                exclude module:'slf4j-log4j12'
                exclude module:'log4j'                
            }
            dependencies {testCompile 'junit:junit:4.12' }            
        }
    }

    repositories {
        mavenCentral()
    }
复制代码

调度服务bulid.gralde:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
 
ext {
    springCloudVersion = 'Edgware.SR4'
}
 
dependencies {
    compile 'org.springframework.cloud:spring-cloud-starter-eureka-server'
    compile 'org.springframework:springloaded'
    compile 'org.springframework.boot:spring-boot-devtools'
}
 
dependencyManagement {
    imports {
        mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
    }
}

服务启动类:

复制代码
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

@SpringBootApplication
@EnableEurekaServer
public class RegistrationServer {
    
    public static void main(String[] args) {
        SpringApplication.run(RegistrationServer.class, args);
    }
}
复制代码

app.yml配置:

1
2
3
4
5
6
7
8
9
10
11
12
server:
  port: 8761
 
eureka:
  instance:
    hostname: localhost
  client:
    register-with-eureka: false
    fetch-registry: false
    service-url:
      defaultZone: http://localhost:${server.port}/eureka/
      

启动服务,访问http://127.0.0.1:8761/eureka

注册中心启动完成;

 

posted @   凉城  阅读(817)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
点击右上角即可分享
微信分享提示