SpringCloud:Eureka Config项目搭建(Gradle项目)

本文详细介绍了Spring Cloud中EurekaConfig的使用方法,包括ConfigServer和ConfigClient的配置过程,以及如何通过git仓库进行远程配置,并实现了配置的自动刷新。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Eureka Config分为Config Server 和Config Client两部分。

Config Server部分:

gradle配置:

 

// https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-config-server
    compile group: 'org.springframework.cloud', name: 'spring-cloud-config-server', version: '2.0.2.RELEASE'

    // https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-eureka-server
    compile group: 'org.springframework.cloud', name: 'spring-cloud-starter-eureka-server', version: '1.4.6.RELEASE'

 

 

 

application.yml:

eureka:
    client:
        serviceUrl:
            defaultZone: http://localhost:8761/eureka/
server:
  port: 8888

spring:
  cloud:
    config:
      server:
        git:
          uri: https://gitee.com/bensonlim/springcloud/
          searchPaths: helloworldConfig
  application:
    name: config-server

 

EurekaconfigApplication.java
@EnableEurekaServer
@EnableConfigServer
@SpringBootApplication
public class EurekaconfigApplication {

	public static void main(String[] args) {
		SpringApplication.run(EurekaconfigApplication.class, args);
	}

}

  

 

Config Client部分:

 

application.yml:

spring:
  application:
    name: config-client
  cloud:
    config:
      label: master
      profile: dev
      uri: http://localhost:8888/
server:
  port: 8881
ConfigclientApplication.java
@SpringBootApplication
@RestController
public class ConfigclientApplication {

	public static void main(String[] args) {
		SpringApplication.run(ConfigclientApplication.class, args);
	}

	@Value("${hello}")
	String hello;
	@RequestMapping(value = "/hello")
	public String hello(){
		return hello;
	}

}

  

 

https://gitee.com/bensonlim/springcloud/tree/master/helloworldConfig

 

配置自动刷新:

引入acurator

 

转载于:https://www.cnblogs.com/bensonlim/p/10243210.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值