微服务springCloud-SpringCloudConfig与Eureka的配合使用

Spring Cloud Config与Eureka配合使用

1.将Config Server和Config Client都注册到Eureka Server上。

spring:
    application:
        #d对应config server所获取的配置文件的{application}
        name: foo
    cloud:
        config:
            uri: http://localhost:8080/
            #profile对应config server所获取的配置文件中的{profile}
            profile: dev
            #指定Git仓库的分支,对应config server所获取的配置文件的{label}
            label: master
                        discovery:
                #表示使用服务发现组件中的Config Server,而不是自己指定的Config Server的uri,默认为false
                enabled: true
                #指定Config Server在服务发现中的serviceId,默认是configserver
                service-id: eureka
eureka:
    client:
        serviceUrl:
            defaultZone: http://localhost:8761/eureka/

简要说明一下bootstrap.yml中的配置属性:
spring.cloud.config.discovery.enabled = true:表示开启通过服务发现组件访问Config Server的功能;
spring.cloud.config.discovery.service-id:指定Config Server在服务发现组件中serviceId;

SpringCould Config的用户认证

1.复制项目microservice-config-server,将ArtifactId修改为microservice-config-server-authenticating。
2.为项目添加以下依赖。

		<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>

3.在application.yml添加以下内容

spring:
    security:
        basic:
            enabled: true    #开启基于HTTP basic的认证
        user:
            name: user                  #配置登录账号
            password: password123      #配置登录密码

这样酒味Config Server添加了基于HTTP basic的认证。如果不设置这段内容,账号就默认是user,密码是一个随机值,该值会在启动时打印出来。

Config Client连接需用户认证的Config Server

方式一:使用curl风格的Url。实例:

spring:
	cloud:
		config:
			uri:http://user:password123@localhost:8080/

方式二:指定Config Server的账号与密码。实例:

spring:
	cloud:
		config:
			uri: http://localhost:8080/
			username: user
			password: password123

本文大部分内容转载自周立的《Spring Cloud与Docker微服务架构实战》

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值