Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

spring config server not refreshing properties

I have a spring boot app that uses the config server to load its properties. The properties exist in the src.main/resources/config directory of the config server project.

When I hit the restful endpoint the properties are loaded fine intially then when I change the properties it still displays the old properties value. How do I call the refresh endpoint as when I call the URL? Do I call it on config-service or hello-service? Even though from the logs it looks to have mapped them it still throws this 405 error

config-server

http://localhost:8889/refresh

or hello-service

http://localhost:9001/refresh

I always get the following

Whitelabel Error Page

This application has no explicit mapping for /error, so you are seeing this as a fallback.

Tue Oct 20 10:48:03 BST 2015
There was an unexpected error (type=Method Not Allowed, status=405).
Request method 'GET' not supported

In the config-server at src/main/resources/config I have the following file

hello-service.properties

#very-so-much=testing
very-so-much=testing second time
second-time=checking again

In my hello-service I have the folloiwng

application.class

 @Bean
    @RefreshScope
    CustomerProps customerProps( @Value("${very-so-much}") String exclamations, @Value("${second-time}") String test) {
        CustomerProps p = new CustomerProps();
        //p.setText(exclamations);
        p.setText(test);
        return p;
    }

Controller class

//    @Value("${very-so-much}")
//    private String prop;
//    
//    @Value("${second-time}")
//    private String anotheerProp;

    @Autowired
    public GreetingController(CustomerRepository repository, GridFsTemplate gridFileSystem, CustomerProps props) {
        this.repository = repository;
        this.fs = gridFileSystem;
        this.props = props;
    }

    @RequestMapping("/greeting")
    public Greeting greeting(@RequestParam(value="name", defaultValue="World") String name) {
        name = props.getText();
        return new Greeting(counter.incrementAndGet(),
                            String.format(template, name));
    }

The start up logs for config-server show the endpoints below

    2015-10-20 10:25:49.616  INFO 13120 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/health],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.HealthMvcEndpoint.invoke(java.security.Principal)
    2015-10-20 10:25:49.617  INFO 13120 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/restart],methods=[POST],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.Object org.springframework.cloud.context.restart.RestartMvcEndpoint.invoke()
    2015-10-20 10:25:49.618  INFO 13120 --- [           main] 
o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/env],methods=[POST],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.Object org.springframework.cloud.context.environment.EnvironmentManagerMvcEndpoint.value(java.util.Map<java.lang.String, java.lang.String>)
    2015-10-20 10:25:49.618  INFO 13120 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/env/reset],methods=[POST],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.util.Map<java.lang.String, java.lang.Object> org.springframework.cloud.context.environment.EnvironmentManagerMvcEndpoint.reset()
    2015-10-20 10:25:49.619  INFO 13120 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/mappings],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
    2015-10-20 10:25:49.619  INFO 13120 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/beans],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
    2015-10-20 10:25:49.620  INFO 13120 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/metrics/{name:.*}],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.MetricsMvcEndpoint.value(java.lang.String)
    2015-10-20 10:25:49.620  INFO 13120 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/metrics],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
    2015-10-20 10:25:49.620  INFO 13120 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/autoconfig],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
    2015-10-20 10:25:49.620  INFO 13120 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/info],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
    2015-10-20 10:25:49.626  INFO 13120 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/refresh],methods=[POST],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.Object org.springframework.cloud.endpoint.GenericPostableMvcEndpoint.invoke()
    2015-10-20 10:25:49.628  INFO 13120 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/env/{name:.*}],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EnvironmentMvcEndpoint.value(java.lang.String)
    2015-10-20 10:25:49.629  INFO 13120 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/env],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
    2015-10-20 10:25:49.629  INFO 13120 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/configprops],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
    2015-10-20 10:25:49.697  INFO 13120 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
    2015-10-20 10:25:49.710  INFO 13120 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Bean with name 'refreshEndpoint' has been autodetected for JMX exposure
    2015-10-20 10:25:49.712  INFO 13120 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Bean with name 'restartEndpoint' has been autodetected for JMX exposure
    2015-10-20 10:25:49.712  INFO 13120 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Bean with name 'configurationPropertiesRebinder' has been autodetected for JMX exposure
    2015-10-20 10:25:49.714  INFO 13120 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Bean with name 'refreshScope' has been autodetected for JMX exposure
    2015-10-20 10:25:49.715  INFO 13120 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Bean with name 'environmentManager' has been autodetected for JMX exposure
    2015-10-20 10:25:49.721  INFO 13120 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Located managed bean 'environmentManager': registering with JMX server as MBean [org.springframework.cloud.context.environment:name=environmentManager,type=EnvironmentManager]
    2015-10-20 10:25:49.751  INFO 13120 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Located managed bean 'restartEndpoint': registering with JMX server as MBean [org.springframework.cloud.context.restart:name=restartEndpoint,type=RestartEndpoint]
    2015-10-20 10:25:49.760  INFO 13120 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Located managed bean 'refreshScope': registering with JMX server as MBean [org.springframework.cloud.context.scope.refresh:name=refreshScope,type=RefreshScope]
    2015-10-20 10:25:49.768  INFO 13120 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Located managed bean 'configurationPropertiesRebinder': registering with JMX server as MBean [org.springframework.cloud.context.properties:name=configurationPropertiesRebinder,type=ConfigurationPropertiesRebinder]
    2015-10-20 10:25:49.787  INFO 13120 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Located managed bean 'refreshEndpoint': registering with JMX server as MBean [org.springframework.cloud.bootstrap.config:name=refreshEndpoint,type=RefreshEndpoint]
    2015-10-20 10:25:49.791  INFO 13120 --- [           main] o.s.c.support.DefaultLifecycleProcessor  : Starting beans in phase 0
    2015-10-20 10:25:49.897  INFO 13120 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8889 (http)
    2015-10-20 10:25:49.898  INFO 13120 --- [           main] doge.ConfigurationServerApplication      : Started ConfigurationServerApplication in 4.485 seconds (JVM running for 5.233)
    2015

And my hello-service logs show below

2015-10-20 10:36:24.822  INFO 11564 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@2eea88a1: startup date [Tue Oct 20 10:36:21 BST 2015]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@400cff1a
2015-10-20 10:36:24.886  INFO 11564 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/customer],methods=[POST],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto org.springframework.http.ResponseEntity<?> hello.GreetingController.add(hello.Customer)
2015-10-20 10:36:24.887  INFO 11564 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/customer/add],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public hello.Customer hello.GreetingController.insertCustomer(java.lang.String,java.lang.String)
2015-10-20 10:36:24.887  INFO 11564 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/customer/greeting],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public hello.Greeting hello.GreetingController.greeting(java.lang.String)
2015-10-20 10:36:24.887  INFO 11564 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/customer/{lastName}],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.http.ResponseEntity<?> hello.GreetingController.readCustomer(java.lang.String)
2015-10-20 10:36:24.889  INFO 11564 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2015-10-20 10:36:24.889  INFO 11564 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],methods=[],params=[],headers=[],consumes=[],produces=[text/html],custom=[]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest)
2015-10-20 10:36:24.914  INFO 11564 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2015-10-20 10:36:24.914  INFO 11564 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2015-10-20 10:36:24.947  INFO 11564 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2015-10-20 10:36:25.333  INFO 11564 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/info],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2015-10-20 10:36:25.333  INFO 11564 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/trace],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2015-10-20 10:36:25.334  INFO 11564 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/restart],methods=[POST],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.Object org.springframework.cloud.context.restart.RestartMvcEndpoint.invoke()
2015-10-20 10:36:25.334  INFO 11564 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/health],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.HealthMvcEndpoint.invoke(java.security.Principal)
2015-10-20 10:36:25.334  INFO 11564 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/pause],methods=[POST],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.Object org.springframework.cloud.endpoint.GenericPostableMvcEndpoint.invoke()
2015-10-20 10:36:25.335  INFO 11564 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/metrics/{name:.*}],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.MetricsMvcEndpoint.value(java.lang.String)
2015-10-20 10:36:25.335  INFO 11564 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/metrics],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2015-10-20 10:36:25.335  INFO 11564 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/refresh],methods=[POST],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.Object org.springframework.cloud.endpoint.GenericPostableMvcEndpoint.invoke()
2015-10-20 10:36:25.336  INFO 11564 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/resume],methods=[POST],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.Object org.springframework.cloud.endpoint.GenericPostableMvcEndpoint.invoke()
2015-10-20 10:36:25.336  INFO 11564 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/dump],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2015-10-20 10:36:25.336  INFO 11564 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/autoconfig],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2015-10-20 10:36:25.337  INFO 11564 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/env],methods=[POST],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.Object org.springframework.cloud.context.environment.EnvironmentManagerMvcEndpoint.value(java.util.Map<java.lang.String, java.lang.String>)
2015-10-20 10:36:25.337  INFO 11564 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/env/reset],methods=[POST],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.util.Map<java.lang.String, java.lang.Object> org.springframework.cloud.context.environment.EnvironmentManagerMvcEndpoint.reset()
2015-10-20 10:36:25.338  INFO 11564 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/env/{name:.*}],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EnvironmentMvcEndpoint.value(java.lang.String)
2015-10-20 10:36:25.338  INFO 11564 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/env],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2015-10-20 10:36:25.338  INFO 11564 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/mappings],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2015-10-20 10:36:25.338  INFO 11564 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/beans],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2015-10-20 10:36:25.338  INFO 11564 --- [           main] o.s.b.a.e.mvc.EndpointHandlerMapping     : Mapped "{[/configprops],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2015-10-20 10:36:25.373  INFO 11564 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2015-10-20 10:36:25.380  INFO 11564 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Bean with name 'refreshEndpoint' has been autodetected for JMX exposure
2015-10-20 10:36:25.380  INFO 11564 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Bean with name 'restartEndpoint' has been autodetected for JMX exposure
2015-10-20 10:36:25.381  INFO 11564 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Bean with name 'configurationPropertiesRebinder' has been autodetected for JMX exposure
2015-10-20 10:36:25.381  INFO 11564 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Bean with name 'refreshScope' has been autodetected for JMX exposure
2015-10-20 10:36:25.382  INFO 11564 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Bean with name 'environmentManager' has been autodetected for JMX exposure
2015-10-20 10:36:25.384  INFO 11564 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Located managed bean 'environmentManager': registering with JMX server as MBean [org.springframework.cloud.context.environment:name=environmentManager,type=EnvironmentManager]
2015-10-20 10:36:25.398  INFO 11564 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Located managed bean 'restartEndpoint': registering with JMX server as MBean [org.springframework.cloud.context.restart:name=restartEndpoint,type=RestartEndpoint]
2015-10-20 10:36:25.405  INFO 11564 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Located managed bean 'refreshScope': registering with JMX server as MBean [org.springframework.cloud.context.scope.refresh:name=refreshScope,type=RefreshScope]
2015-10-20 10:36:25.411  INFO 11564 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Located managed bean 'configurationPropertiesRebinder': registering with JMX server as MBean [org.springframework.cloud.context.properties:name=configurationPropertiesRebinder,type=ConfigurationPropertiesRebinder]
2015-10-20 10:36:25.425  INFO 11564 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Located managed bean 'refreshEndpoint': registering with JMX server as MBean [org.springframework.cloud.bootstrap.config:name=refreshEndpoint,type=RefreshEndpoint]
2015-10-20 10:36:25.431  INFO 11564 --- [           main] o.s.c.support.DefaultLifecycleProcessor  : Starting beans in phase 0
2015-10-20 10:36:25.529  INFO 11564 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 9001 (http)

Thanks

like image 365
user1107753 Avatar asked Oct 20 '15 09:10

user1107753


People also ask

How to refresh properties in config clients in Spring Cloud?

In the case of using Spring Cloud Config Server; Spring Cloud offers the following methods to refresh the properties in config clients. By calling the /actuator/refresh endpoint exposed on the config client via the Spring Actuator. By calling the /actuator/bus-refresh endpoint exposed on the config client integrated with Spring Cloud Bus.

How to refresh the properties in the application context in spring?

When it comes to refreshing the properties in the application context, there are two steps again; reloading the property sources in the Environment and refreshing the attributes of Spring beans. In the case of using Spring Cloud Config Server; Spring Cloud offers the following methods to refresh the properties in config clients.

How does the config client refresh the config server?

The config client makes a request to the config server with the config server URL and refreshes itself. The config client broadcasts a refresh event to the other services over the message broker. The services received the refresh event also make a request to the config server to fetch the up-to-date configuration data.

How do I find the location of a spring config file?

Then, we'll tell Spring where it is with the command-line parameter –spring.config.location=file:// {path to file}. Or, we can put it in application.properties. In file-based properties, we'll have to choose a way to reload the file.


1 Answers

As this is a POST request and thus running a curl command as below

curl -d {} http://localhost:9001/refresh

did refresh my properties.

like image 149
user1107753 Avatar answered Oct 21 '22 18:10

user1107753