如何将 Zuul 网关配置移动到配置服务器

How to move Zuul gateway configurations to configuration server

我从微服务架构和 spring 云开始。 我正在尝试从 spring 配置服务器获取我的 Spring Zuul 网关的配置。 我在网关服务的 bootstrap.properties 文件中添加了以下属性:

spring.application.name=api-gateway

spring.cloud.config.uri=http://localhost:8888

spring.profiles.active=dev

尽管这些属性适用于所有其他服务,但它们不适用于网关。 我为网关使用的注释是:

@EnableZuulProxy
@EnableDiscoveryClient
@SpringBootApplication
public class ApiGatewayApplication {

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

}

其他服务的注解只有:

@SpringBootApplication

我的配置服务器有一个已连接的 git 存储库,其中包含一个文件:api-gateway-dev.properties

网关日志:

:: Spring Boot :: (v2.3.0.M4)

2020-04-17 21:42:39.983 INFO 10340 --- [ restartedMain] c.nyo.apigateway.ApiGatewayApplication : The following profiles are active: dev 2020-04-17 21:42:41.926 WARN 10340 --- [ restartedMain] o.s.boot.actuate.endpoint.EndpointId : Endpoint ID 'service-registry' contains invalid characters, please migrate to a valid format. 2020-04-17 21:42:41.969 WARN 10340 --- [ restartedMain] o.s.boot.actuate.endpoint.EndpointId : Endpoint ID 'hystrix.stream' contains invalid characters, please migrate to a valid format. 2020-04-17 21:42:42.240 INFO 10340 --- [ restartedMain] o.s.cloud.context.scope.GenericScope : BeanFactory id=a11a283e-7de6-3470-b177-65c08eab7398 2020-04-17 21:42:43.859 INFO 10340 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8765 (http) 2020-04-17 21:42:43.880 INFO 10340 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]

正在获取配置的服务的日志:

:: Spring Boot :: (v2.3.0.M4)

2020-04-17 21:54:01.414 INFO 5180 --- [ restartedMain] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://localhost:8888 2020-04-17 21:54:04.184 INFO 5180 --- [ restartedMain] c.c.c.ConfigServicePropertySourceLocator : Located environment: name=users-service, profiles=[dev], label=null, version=244114f5a11aa7d4a0acb5750ddad144f7de1be5, state=null 2020-04-17 21:54:04.186 INFO 5180 --- [ restartedMain] b.c.PropertySourceBootstrapConfiguration : Located property source: [BootstrapPropertySource {name='bootstrapProperties-configClient'}, BootstrapPropertySource {name='bootstrapProperties-https://my-user@bitbucket.org/my-user/configs.git/users-service-dev.properties'}, BootstrapPropertySource {name='bootstrapProperties-https://my-user@bitbucket.org/my-user/configs.git/users-service.properties'}] 2020-04-17 21:54:04.197 INFO 5180 --- [ restartedMain] c.n.U.UsersServiceApplication : The following profiles are active: dev

  1. 使网关配置动态化合乎逻辑吗?

  2. 为什么我不能从配置服务器获取配置?

找到问题了。我失踪了:

implementation 'org.springframework.cloud:spring-cloud-starter-config'

在我的 build.gradle 文件依赖项中