【发布时间】:2020-07-30 15:21:27
【问题描述】:
我从微服务架构和 Spring Cloud 开始。 我正在尝试从 spring 配置服务器获取我的 Spring Zuul Gateway 的配置。 我在网关服务的 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 信息 10340 --- [restartedMain] c.nyo.apigateway.ApiGatewayApplication :以下配置文件是 活动:开发 2020-04-17 21:42:41.926 WARN 10340 --- [restartedMain] os.boot.actuate.endpoint.EndpointId :端点 ID 'service-registry' 包含无效字符,请迁移到 有效的格式。 2020-04-17 21:42:41.969 警告 10340 --- [ restartedMain] os.s.boot.actuate.endpoint.EndpointId : 端点 ID “hystrix.stream”包含无效字符,请迁移到 有效的格式。 2020-04-17 21:42:42.240 信息 10340 --- [ restartedMain] os.cloud.context.scope.GenericScope : BeanFactory id=a11a283e-7de6-3470-b177-65c08eab7398 2020-04-17 21:42:43.859 信息 10340 --- [restartedMain] os.b.w.embedded.tomcat.TomcatWebServer: Tomcat 使用端口初始化:8765 (http) 2020-04-17 21:42:43.880 信息 10340 --- [restartedMain] o.apache.catalina.core.StandardService : 启动服务 [Tomcat]
获取配置的服务日志:
:: Spring Boot :: (v2.3.0.M4)
2020-04-17 21:54:01.414 信息 5180 --- [restartedMain] c.c.c.ConfigServicePropertySourceLocator : 从服务器获取配置 在:http://localhost:88882020-04-17 21:54:04.184 信息 5180 --- [ restartedMain] c.c.c.ConfigServicePropertySourceLocator :位于 环境:name=users-service,profiles=[dev],label=null, 版本=244114f5a11aa7d4a0acb5750ddad144f7de1be5,状态=null 2020-04-17 21:54:04.186 信息 5180 --- [restartedMain] b.c.PropertySourceBootstrapConfiguration :定位的属性源: [BootstrapPropertySource {name='bootstrapProperties-configClient'}, 引导属性源 {name='bootstrapProperties-https://my-user@bitbucket.org/my-user/configs.git/users-service-dev.properties'}, 引导属性源 {name='bootstrapProperties-https://my-user@bitbucket.org/my-user/configs.git/users-service.properties'}] 2020-04-17 21:54:04.197 信息 5180 --- [restartedMain] c.n.U.UsersServiceApplication :以下配置文件是 活跃:开发
使网关配置动态化是否合乎逻辑?
为什么我没有从配置服务器获取配置?
【问题讨论】:
-
是的,它应该可以工作。什么不起作用?应该有尝试连接到配置服务器的日志条目,你可以添加这些吗?可以打localhost:8888/api-gateway/dev吗?
-
我添加了日志
标签: spring spring-boot microservices spring-cloud netflix-zuul