@RefreshScope not working. Properties are not updated after being modified the second time in Consul





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I am working with Consul using spring-cloud-consul and currently have this problem. I create a key in consul as config/ConsulServer/my/username with value as "bob". In my controller, i return this value if a API call "/foo" is made. When i modified it the first time to "steve" the value is updated and i get "steve". However, it does not work the second time. The value is still "steve". Could anyone please help on what I did wrong ? My codes are



@SpringBootApplication
@EnableDiscoveryClient
public class ConsulServer {
public static void main(String args) {
SpringApplication.run(ConsulServer.class, args);
}
}

@Component
@RefreshScope
@ConfigurationProperties("my")
public class SampleProperties {
private String username;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username= username;
}
}

@RestController
public class ConsulController {
@Autowired
private SampleProperties consulConfig;

@GetMapping("/foo")
public String prop() {
return this.consulConfig.getUsername();
}
}


My bootstrap.yml is



spring:
application:
name: ConsulServer
cloud:
consul:
host: localhost
port: 8500
config:
enabled: true
fail-fast: true
watch:
enabled: true
discovery:
register: true


My application.yml is



spring:
application:
name: ConsulServer


I am using spring-cloud-starter-consul-all version 2.1.0.RC3










share|improve this question























  • strange, tried your configuration with Consul (version 1.2.1) and spring-cloud-starter-consul-all (version 2.1.0.RC3) - works as expected, value is changed every time. Did you check logs? I have "o.s.c.e.event.RefreshEventListener : Refresh keys changed: [my.username]" every time after when I change value in Consul UI

    – nmyk
    Jan 4 at 8:41











  • Hi @nmyk, thanks for your help. I also see that event in the logs when I changed the consul but the value is not updated when I make the API call to /foo

    – Steven
    Jan 5 at 16:09













  • I notice that it work with @Value though. That is if I map my.username directly to a String field, then that field is updated with new value.

    – Steven
    Jan 5 at 16:14


















0















I am working with Consul using spring-cloud-consul and currently have this problem. I create a key in consul as config/ConsulServer/my/username with value as "bob". In my controller, i return this value if a API call "/foo" is made. When i modified it the first time to "steve" the value is updated and i get "steve". However, it does not work the second time. The value is still "steve". Could anyone please help on what I did wrong ? My codes are



@SpringBootApplication
@EnableDiscoveryClient
public class ConsulServer {
public static void main(String args) {
SpringApplication.run(ConsulServer.class, args);
}
}

@Component
@RefreshScope
@ConfigurationProperties("my")
public class SampleProperties {
private String username;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username= username;
}
}

@RestController
public class ConsulController {
@Autowired
private SampleProperties consulConfig;

@GetMapping("/foo")
public String prop() {
return this.consulConfig.getUsername();
}
}


My bootstrap.yml is



spring:
application:
name: ConsulServer
cloud:
consul:
host: localhost
port: 8500
config:
enabled: true
fail-fast: true
watch:
enabled: true
discovery:
register: true


My application.yml is



spring:
application:
name: ConsulServer


I am using spring-cloud-starter-consul-all version 2.1.0.RC3










share|improve this question























  • strange, tried your configuration with Consul (version 1.2.1) and spring-cloud-starter-consul-all (version 2.1.0.RC3) - works as expected, value is changed every time. Did you check logs? I have "o.s.c.e.event.RefreshEventListener : Refresh keys changed: [my.username]" every time after when I change value in Consul UI

    – nmyk
    Jan 4 at 8:41











  • Hi @nmyk, thanks for your help. I also see that event in the logs when I changed the consul but the value is not updated when I make the API call to /foo

    – Steven
    Jan 5 at 16:09













  • I notice that it work with @Value though. That is if I map my.username directly to a String field, then that field is updated with new value.

    – Steven
    Jan 5 at 16:14














0












0








0


0






I am working with Consul using spring-cloud-consul and currently have this problem. I create a key in consul as config/ConsulServer/my/username with value as "bob". In my controller, i return this value if a API call "/foo" is made. When i modified it the first time to "steve" the value is updated and i get "steve". However, it does not work the second time. The value is still "steve". Could anyone please help on what I did wrong ? My codes are



@SpringBootApplication
@EnableDiscoveryClient
public class ConsulServer {
public static void main(String args) {
SpringApplication.run(ConsulServer.class, args);
}
}

@Component
@RefreshScope
@ConfigurationProperties("my")
public class SampleProperties {
private String username;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username= username;
}
}

@RestController
public class ConsulController {
@Autowired
private SampleProperties consulConfig;

@GetMapping("/foo")
public String prop() {
return this.consulConfig.getUsername();
}
}


My bootstrap.yml is



spring:
application:
name: ConsulServer
cloud:
consul:
host: localhost
port: 8500
config:
enabled: true
fail-fast: true
watch:
enabled: true
discovery:
register: true


My application.yml is



spring:
application:
name: ConsulServer


I am using spring-cloud-starter-consul-all version 2.1.0.RC3










share|improve this question














I am working with Consul using spring-cloud-consul and currently have this problem. I create a key in consul as config/ConsulServer/my/username with value as "bob". In my controller, i return this value if a API call "/foo" is made. When i modified it the first time to "steve" the value is updated and i get "steve". However, it does not work the second time. The value is still "steve". Could anyone please help on what I did wrong ? My codes are



@SpringBootApplication
@EnableDiscoveryClient
public class ConsulServer {
public static void main(String args) {
SpringApplication.run(ConsulServer.class, args);
}
}

@Component
@RefreshScope
@ConfigurationProperties("my")
public class SampleProperties {
private String username;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username= username;
}
}

@RestController
public class ConsulController {
@Autowired
private SampleProperties consulConfig;

@GetMapping("/foo")
public String prop() {
return this.consulConfig.getUsername();
}
}


My bootstrap.yml is



spring:
application:
name: ConsulServer
cloud:
consul:
host: localhost
port: 8500
config:
enabled: true
fail-fast: true
watch:
enabled: true
discovery:
register: true


My application.yml is



spring:
application:
name: ConsulServer


I am using spring-cloud-starter-consul-all version 2.1.0.RC3







spring-boot consul spring-cloud-consul






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 3 at 12:59









StevenSteven

648




648













  • strange, tried your configuration with Consul (version 1.2.1) and spring-cloud-starter-consul-all (version 2.1.0.RC3) - works as expected, value is changed every time. Did you check logs? I have "o.s.c.e.event.RefreshEventListener : Refresh keys changed: [my.username]" every time after when I change value in Consul UI

    – nmyk
    Jan 4 at 8:41











  • Hi @nmyk, thanks for your help. I also see that event in the logs when I changed the consul but the value is not updated when I make the API call to /foo

    – Steven
    Jan 5 at 16:09













  • I notice that it work with @Value though. That is if I map my.username directly to a String field, then that field is updated with new value.

    – Steven
    Jan 5 at 16:14



















  • strange, tried your configuration with Consul (version 1.2.1) and spring-cloud-starter-consul-all (version 2.1.0.RC3) - works as expected, value is changed every time. Did you check logs? I have "o.s.c.e.event.RefreshEventListener : Refresh keys changed: [my.username]" every time after when I change value in Consul UI

    – nmyk
    Jan 4 at 8:41











  • Hi @nmyk, thanks for your help. I also see that event in the logs when I changed the consul but the value is not updated when I make the API call to /foo

    – Steven
    Jan 5 at 16:09













  • I notice that it work with @Value though. That is if I map my.username directly to a String field, then that field is updated with new value.

    – Steven
    Jan 5 at 16:14

















strange, tried your configuration with Consul (version 1.2.1) and spring-cloud-starter-consul-all (version 2.1.0.RC3) - works as expected, value is changed every time. Did you check logs? I have "o.s.c.e.event.RefreshEventListener : Refresh keys changed: [my.username]" every time after when I change value in Consul UI

– nmyk
Jan 4 at 8:41





strange, tried your configuration with Consul (version 1.2.1) and spring-cloud-starter-consul-all (version 2.1.0.RC3) - works as expected, value is changed every time. Did you check logs? I have "o.s.c.e.event.RefreshEventListener : Refresh keys changed: [my.username]" every time after when I change value in Consul UI

– nmyk
Jan 4 at 8:41













Hi @nmyk, thanks for your help. I also see that event in the logs when I changed the consul but the value is not updated when I make the API call to /foo

– Steven
Jan 5 at 16:09







Hi @nmyk, thanks for your help. I also see that event in the logs when I changed the consul but the value is not updated when I make the API call to /foo

– Steven
Jan 5 at 16:09















I notice that it work with @Value though. That is if I map my.username directly to a String field, then that field is updated with new value.

– Steven
Jan 5 at 16:14





I notice that it work with @Value though. That is if I map my.username directly to a String field, then that field is updated with new value.

– Steven
Jan 5 at 16:14












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54022796%2frefreshscope-not-working-properties-are-not-updated-after-being-modified-the-s%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54022796%2frefreshscope-not-working-properties-are-not-updated-after-being-modified-the-s%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Can a sorcerer learn a 5th-level spell early by creating spell slots using the Font of Magic feature?

Does disintegrating a polymorphed enemy still kill it after the 2018 errata?

A Topological Invariant for $pi_3(U(n))$