问题
I am using spring-cloud-config-server with SVN as repository. When I start the cloud-config-server and client[microservice], configuration value is picked up properly.
After changing a configuration value and SVN commit, I am firing refresh POST call, URL: http://localhost:8080/actuator/refresh [8080 is client port]. The updated value in SVN is not getting refreshed.
It is known that config-server stores the SVN data locally.[In my case, folder location - /tmp/config-repo-5393789580706388886] The strange thing here is that, the committed change in SVN is updated locally, once the 'refresh' REST call is triggered. But it is just that application is not picking it up.
Spring boot version - 2.1.3.
Cloud version - Greenwich Release.
Config-Server Details:
Maven dependency:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
<groupId>org.tmatesoft.svnkit</groupId>
<artifactId>svnkit</artifactId>
</dependency>
application.yml:
spring:
application:
name: spring-cloud-config-server
profiles:
active: subversion
cloud:
config:
server:
svn:
uri: https://svn.*****.com/repos/****/microservices
username: #####
password: #####
default-label: source
server:
port: 8888
config-client[microservice] details: Maven dependency:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
application.yml:
spring:
application:
name: [client-app-name]
cloud:
config:
uri: http://localhost:8888
management:
endpoints:
web:
exposure:
include: "*"
endpoint:
health:
show-details: ALWAYS
security:
enabled: false
server:
port: 8080
While starting the config-client microservice, able to see that it is fetching the values from the expected SVN location via config-server.
c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://localhost:8888
c.c.c.ConfigServicePropertySourceLocator : Located environment: name=[client-app-name], profiles=[default], label=null, version=10718, state=null
b.c.PropertySourceBootstrapConfiguration : Located property source: CompositePropertySource {name='configService', propertySources=[MapPropertySource {name='configClient'}, MapPropertySource {name='https://svn.*****.com/repos/****/microservices/source/[client-app-name].properties'}]}
While invoking the test REST call to get the configuration value from config client, I am getting the value from SVN.
After doing the change in the file , [client-app-name].properties and committing to SVN. While doing the REST call http://localhost:8080/actuator/refresh, getting the following as response, which is as expected.
[]-bash-4.2$ curl -X POST http://localhost:9000/actuator/refresh
["config.client.version","configValue"]-bash-4.2$
At the same time, getting the following message from logs as expected.
c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://localhost:8888
c.c.c.ConfigServicePropertySourceLocator : Located environment: name=[client-app-name], profiles=[default], label=null, version=10718, state=null
b.c.PropertySourceBootstrapConfiguration : Located property source: CompositePropertySource {name='configService', propertySources=[MapPropertySource {name='configClient'}, MapPropertySource {name='https://svn.*****.com/repos/****/microservices/source/[client-app-name].properties'}]}
The REST call to the config-client , to fetch the updated configuration just returning the previous configuration value.
If I restart the client, it is picking up the updated latest configuration. Also, the SVN change in updated locally[In my case, folder location - /tmp/config-repo-5393789580706388886]
I am really not able to find out the mistake I did. Any inputs to resolve this would be very much helpful. Thanks a lot.
回答1:
Did you set @RefreshScope
annotation to your Component?
For example, TestProperties
is the @ConfigurationProperites
that have configValue.
@Bean
public TestComponent(TestProperties properties) {
return new TestComponent(properties.getConfigValue());
}
If you are using raw configValue like above example, you have to annotate it.
@Bean
public TestComponent(TestProperties properties) {
return new TestComponent(properties);
}
If you are using properties as it is, it would be refreshed.
来源:https://stackoverflow.com/questions/57039622/strange-issue-with-spring-cloud-config-server-with-svn-as-repository