【发布时间】:2018-12-22 09:15:18
【问题描述】:
我有一个使用 @EnableConfigServer 运行的 Spring Config Server,它运行良好
@SpringBootApplication
@EnableConfigServer
public class ConfigServerApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigServerApplication.class, args);
}
}
然后我还有客户端,使用@SpringBootApplication 和@RefreshScope 运行
@SpringBootApplication
@RefreshScope
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
还有我的 RestController
@RestController
@RefreshScope
public class LicenseServiceController {
@Value("${some.property}")
String someProperty;
@GetMapping("/someProperty")
public String getSomeProperty() {
return someProperty;
}
}
现在,我已经让 Config Server 与我的私有 github repo 端点对话以检索配置属性,它做得非常好,例如,如果我点击我的端点 http://localhost:8888/y/default,它会返回这个 sn-p
propertySources: [
{
name: "https://github.com/me/config/x/y.yml",
source: {
some.property: "hi"
}
}
]
一切正常,当我通过@Value 标记点击使用该属性的端点时,从客户端,我返回 hi for @Value(${some.property})
问题是当我更新我的 git 存储库并将 some.property 更改为“再见”时。如果我再次从客户端点击端点,我将再次为 @Value(${some.property}) 返回“hi”而不是“bye”。
在配置服务器端点http://localhost:8888/y/default,然后我得到
propertySources: [
{
name: "https://github.com/me/config/x/y.yml",
source: {
some.property: "bye"
}
}
]
在客户端时,我仍然对 @Value(${some.property}) 感到“嗨” 即使我使用 POST 请求从客户端点击 /actuators/refresh 端点
这是我从客户端(SpringBootApplication)获得的调试日志,在我看来,POST 请求有效,我的 curl 命令也得到了正确的响应,至少我认为
INFO 13493 --- [nio-8080-exec-2] trationDelegate$BeanPostProcessorChecker : Bean 'configurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$b4dd7d61] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
INFO 13493 --- [nio-8080-exec-2] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://localhost:8888
DEBUG 13493 --- [nio-8080-exec-2] o.s.web.client.RestTemplate : Created GET request for "http://localhost:8888/y/default"
DEBUG 13493 --- [nio-8080-exec-2] o.s.web.client.RestTemplate : Setting request Accept header to [application/json, application/*+json]
DEBUG 13493 --- [nio-8080-exec-2] o.s.web.client.RestTemplate : GET request for "http://localhost:8888/y/default" resulted in 200 (null)
DEBUG 13493 --- [nio-8080-exec-2] o.s.web.client.RestTemplate : Reading [class org.springframework.cloud.config.environment.Environment] as "application/json;charset=UTF-8" using [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@2e68f713]
INFO 13493 --- [nio-8080-exec-2] c.c.c.ConfigServicePropertySourceLocator : Located environment: name=y, profiles=[default], label=null, version=948c431771g06325k3520x67k70z74xa2829ts33, state=null
INFO 13493 --- [nio-8080-exec-2] b.c.PropertySourceBootstrapConfiguration : Located property source: CompositePropertySource {name='configService', propertySources=[MapPropertySource {name='configClient'}, MapPropertySource {name='https://github.com/me/tmp-config/x/y.yml'}]}
INFO 13493 --- [nio-8080-exec-2] o.s.boot.SpringApplication : The following profiles are active: default
INFO 13493 --- [nio-8080-exec-2] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@6a81dcff: startup date [Fri Jul 13 21:02:29 EDT 2018]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@7ab876b9
INFO 13493 --- [nio-8080-exec-2] o.s.boot.SpringApplication : Started application in 0.202 seconds (JVM running for 24.359)
DEBUG 13493 --- [nio-8080-exec-2] o.s.w.c.s.StandardServletEnvironment : Replacing PropertySource 'bootstrapProperties' with 'bootstrapProperties'
DEBUG 13493 --- [nio-8080-exec-2] o.s.w.c.s.StandardServletEnvironment : Replacing PropertySource 'random' with 'random'
DEBUG 13493 --- [nio-8080-exec-2] o.s.w.c.s.StandardServletEnvironment : Replacing PropertySource 'applicationConfig: [classpath:/application.yml]' with 'applicationConfig: [classpath:/application.yml]'
DEBUG 13493 --- [nio-8080-exec-2] o.s.w.c.s.StandardServletEnvironment : Replacing PropertySource 'springCloudClientHostInfo' with 'springCloudClientHostInfo'
DEBUG 13493 --- [nio-8080-exec-2] o.s.w.c.s.StandardServletEnvironment : Replacing PropertySource 'applicationConfig: [classpath:/bootstrap.yml]' with 'applicationConfig: [classpath:/bootstrap.yml]'
DEBUG 13493 --- [nio-8080-exec-2] o.s.w.c.s.StandardServletEnvironment : Replacing PropertySource 'defaultProperties' with 'defaultProperties
DEBUG 13493 --- [nio-8080-exec-2] o.s.w.c.s.StandardServletEnvironment : Replacing PropertySource 'defaultProperties' with 'defaultProperties'
INFO 13493 --- [nio-8080-exec-2] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@6a81dcff: startup date [Fri Jul 13 21:02:29 EDT 2018]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@7ab876b9
INFO 13493 --- [nio-8080-exec-2] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@7ab876b9: startup date [Fri Jul 13 21:02:29 EDT 2018]; root of context hierarchy
DEBUG 13493 --- [nio-8080-exec-2] m.m.a.RequestResponseBodyMethodProcessor : Written [[config.client.version, some.property]] as "application/vnd.spring-boot.actuator.v2+json" using [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@67770b37]
DEBUG 13493 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : Null ModelAndView returned to DispatcherServlet with name 'dispatcherServlet': assuming HandlerAdapter completed request handling
DEBUG 13493 --- [nio-8080-exec-2] o.s.web.servlet.DispatcherServlet : Successfully completed request
现在,我能得出的唯一结论是端点 url 错误,因为在日志中显示“https://github.com/me/config/x/y.yml”
但是在提供 404 的浏览器中,因为它应该是“https://github.com/me/config/blob/master/x/y.yml”,但这似乎是 Spring 编写者不太可能出现的错误。似乎我做的一切都正确,但不知何故它仍然坏了
【问题讨论】:
标签: spring spring-mvc spring-boot spring-cloud spring-cloud-config