all: In my env, all configurations store in localfile,so my service configuration file stores in classpath:configs/.
So, when files in classpath:configs/ changes, needing refresh on the fly to provide latest properties, I need automatically refresh all values, How could i fulfill this demand?
Here is my configuration of config server:
application.yml
server:
port: 8003
endpoints:
restart:
enabled: true
refresh:
enabled: true
spring:
cloud:
config:
server:
native:
searchLocations: classpath:/
etcd:
conn:
etcdPassword: 134
etcdUrls:
- http://localhost:2379
etcdUsername: root
enabled: true
etcdServicePrefix: /congiguration/project1/
enabled: true
timeout: 1
bootstrap.yml
spring:
application:
name: configurations
profiles:
active: native
I have an configurations.yml lays in moudule resources dir:
configurations(-default or not).yml
prop1: Hello
prop2: world
etcd:
conn:
etcdPassword: 134
Here is my configuration of config client:
bootstrap.yml
spring:
application:
name: configurations
cloud:
config:
uri: http://localhost:8003/
application.yml
server:
port: 7002
management:
security:
enabled: false
Entrypoint
@RefreshScope
@RestController
class TestController {
@Value("${prop2}")
private String prop2;
@RequestMapping("/prop2")
public String from() {
return this.prop2;
}
}
It could print "world" when visit http://localhost:7002/prop2/ in browser, but when config server resources/configurations.yml changed, then curl -X POST http://localhost:7002/refresh nothing changed and just return [](It should return ["prop2"]) and the same result by visiting http://localhost:7002/prop2/.
logs in console when post /refresh:
Config Server:
017-06-14 19:03:07.301 INFO 69939 --- [nio-8003-exec-4]
s.c.a.AnnotationConfigApplicationContext
Refreshingorg.springframework.context.annotation.
AnnotationConfigApplicationContext@45daa065: startup date [Wed Jun 14 19:03:07
CST 2017]; root of context hierarchy
2017-06-14 19:03:07.320 INFO 69939 --- [nio-8003-exec-4]
o.s.c.c.s.e.NativeEnvironmentRepository : Adding property source:
classpath:configs/configurations.yaml
2017-06-14 19:03:07.320 INFO 69939 --- [nio-8003-exec-4]
s.c.a.AnnotationConfigApplicationContext : Closing
org.springframework.context.annotation.AnnotationConfigApplicationContext
@45daa065: startup date [Wed Jun 14 19:03:07 CST 2017]; root of context
hierarchy
Config Client:
2017-06-14 19:03:07.064 INFO 69942 --- [nio-7002-exec-3]
c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at:
http://localhost:8003/
2017-06-14 19:03:07.322 INFO 69942 --- [nio-7002-exec-3]
c.c.c.ConfigServicePropertySourceLocator : Located environment:
name=configurations, profiles=[default], label=master, version=null
2017-06-14 19:03:07.322 INFO 69942 --- [nio-7002-exec-3]
b.c.PropertySourceBootstrapConfiguration : Located property source:
CompositePropertySource [name='configService', propertySources=
[MapPropertySource [name='classpath:configs/configurations.yaml']]]
2017-06-14 19:03:07.324 INFO 69942 --- [nio-7002-exec-3]
o.s.boot.SpringApplication : No active profile set, falling back
to default profiles: default
2017-06-14 19:03:07.326 INFO 69942 --- [nio-7002-exec-3]
s.c.a.AnnotationConfigApplicationContext : Refreshing
org.springframework.context.annotation.AnnotationConfigApplicationContext
@2ff4dec0: startup date [Wed Jun 14 19:03:07 CST 2017]; parent:
org.springframework.context.annotation.AnnotationConfigApplicationContext@109b
36f8
2017-06-14 19:03:07.336 INFO 69942 --- [nio-7002-exec-3]
o.s.boot.SpringApplication : Started application in 0.511
seconds (JVM running for 231.593)
2017-06-14 19:03:07.336 INFO 69942 --- [nio-7002-exec-3]
s.c.a.AnnotationConfigApplicationContext : Closing
org.springframework.context.annotation.AnnotationConfigApplicationContext@2ff
4dec0: startup date [Wed Jun 14 19:03:07 CST 2017]; parent:
org.springframework.context.annotation.AnnotationConfigApplicationContext@109b
36f8
curl -X POST http://localhost:8000/refresh, return:[]curl -X POST http://localhost:8000/bus/refresh, return: "status":404,"error":"Not Found"so, you mean use this onehttps://github.com/spring-cloud/spring-cloud-busto fulfill my demand?nativeprofile is not activated in your configuration, are you activating that profile? The default search location when that profile is active is the classpath so there is no need to specify that.localhost:9000, my config client islocalhost:8000, i fresh throughcurl -X POST http://localhost:8000/refresh, does this correct ?bootstrap.ymlfile for the config server or the config client. Thenativeprofile should be enabled on the config server. I am confused because you havespring.application.nameset toconfigurations in thebootstrap.yml` file and the then have a configuration file calledconfigurations.yml. I assumeconfigurations.ymlis the configuration for the config client, no?