2016-06-26 24 views
0

ich eine sehr einfache Federwolke App haben, wie folgt:Config Wert nicht geändert Auto im Frühjahr Wolke Konsul

@SpringBootApplication 
@EnableDiscoveryClient 
@RestController 
@EnableAutoConfiguration 
public class SpringCloudConsulDemoApplication { 

    public static void main(String[] args) { 
     new SpringApplicationBuilder(SpringCloudConsulDemoApplication.class).web(true).run(args); 
    } 

    @Value("${my.message}") 
    private String message; 

    @RequestMapping("/") 
    public String home() { 
     return message; 
    } 

    @RequestMapping("/health") 
    public String health() { 
     return "Hello world"; 
    } 
} 

ich Config die "my.message" in Konsul unter/config/SpringCloudConsulDemo, dev /. Wenn ich den Wert von „my.message“ geändert, bekam ich eine Ausgabe im Frühjahr Cloud App:

2016-06-26 12:41:18.621 INFO 1187 --- [pool-1-thread-1] s.c.a.AnnotationConfigApplicationContext : Refreshing org.spring[email protected]601c9895: startup date [Sun Jun 26 12:41:18 CST 2016]; root of context hierarchy 
2016-06-26 12:41:18.631 INFO 1187 --- [pool-1-thread-1] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring 
2016-06-26 12:41:18.632 INFO 1187 --- [pool-1-thread-1] trationDelegate$BeanPostProcessorChecker : Bean 'configurationPropertiesRebinderAutoConfiguration' of type [class org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$7facc2d7] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 
2016-06-26 12:41:18.687 INFO 1187 --- [pool-1-thread-1] b.c.PropertySourceBootstrapConfiguration : Located property source: CompositePropertySource [name='consul', propertySources=[[email protected] [name='config/SpringCloudConsulDemo,dev/', [email protected]], [email protected] [name='config/SpringCloudConsulDemo/', [email protected]], [email protected] [name='config/application,dev/', [email protected]], [email protected] [name='config/application/', [email protected]]]] 
2016-06-26 12:41:18.691 INFO 1187 --- [pool-1-thread-1] o.s.boot.SpringApplication    : The following profiles are active: dev 
2016-06-26 12:41:18.692 INFO 1187 --- [pool-1-thread-1] s.c.a.AnnotationConfigApplicationContext : Refreshing org.spring[email protected]e4a3026: startup date [Sun Jun 26 12:41:18 CST 2016]; parent: org.spring[email protected]601c9895 
2016-06-26 12:41:18.693 INFO 1187 --- [pool-1-thread-1] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring 
2016-06-26 12:41:18.699 INFO 1187 --- [pool-1-thread-1] o.s.boot.SpringApplication    : Started application in 0.123 seconds (JVM running for 1113.16) 
2016-06-26 12:41:18.699 INFO 1187 --- [pool-1-thread-1] s.c.a.AnnotationConfigApplicationContext : Closing org.spring[email protected]e4a3026: startup date [Sun Jun 26 12:41:18 CST 2016]; parent: org.spring[email protected]601c9895 
2016-06-26 12:41:18.699 INFO 1187 --- [pool-1-thread-1] s.c.a.AnnotationConfigApplicationContext : Closing org.spring[email protected]601c9895: startup date [Sun Jun 26 12:41:18 CST 2016]; root of context hierarchy 
2016-06-26 12:41:18.758 DEBUG 1187 --- [pool-1-thread-1] o.s.c.c.discovery.HeartbeatProperties : Computed heartbeatInterval: PT20S 
2016-06-26 12:41:18.808 INFO 1187 --- [pool-1-thread-1] o.s.c.e.event.RefreshEventListener  : Refresh keys changed: [spring.cloud.client.hostname, my.message] 

ich gerade auch die POST-Methode von/Refresh aufrufen und eine Ausgabe erhalten:

2016-06-26 12:44:12.962 INFO 1187 --- [nio-8093-exec-3] s.c.a.AnnotationConfigApplicationContext : Refreshing org.spring[email protected]2757ca3e: startup date [Sun Jun 26 12:44:12 CST 2016]; root of context hierarchy 
2016-06-26 12:44:12.974 INFO 1187 --- [nio-8093-exec-3] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring 
2016-06-26 12:44:12.978 INFO 1187 --- [nio-8093-exec-3] trationDelegate$BeanPostProcessorChecker : Bean 'configurationPropertiesRebinderAutoConfiguration' of type [class org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$7facc2d7] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying) 
2016-06-26 12:44:13.056 INFO 1187 --- [nio-8093-exec-3] b.c.PropertySourceBootstrapConfiguration : Located property source: CompositePropertySource [name='consul', propertySources=[[email protected] [name='config/SpringCloudConsulDemo,dev/', [email protected]], [email protected] [name='config/SpringCloudConsulDemo/', [email protected]], [email protected] [name='config/application,dev/', [email protected]], [email protected] [name='config/application/', [email protected]]]] 
2016-06-26 12:44:13.060 INFO 1187 --- [nio-8093-exec-3] o.s.boot.SpringApplication    : The following profiles are active: dev 
2016-06-26 12:44:13.060 INFO 1187 --- [nio-8093-exec-3] s.c.a.AnnotationConfigApplicationContext : Refreshing org.spring[email protected]f738b82: startup date [Sun Jun 26 12:44:13 CST 2016]; parent: org.spring[email protected]2757ca3e 
2016-06-26 12:44:13.061 INFO 1187 --- [nio-8093-exec-3] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring 
2016-06-26 12:44:13.066 INFO 1187 --- [nio-8093-exec-3] o.s.boot.SpringApplication    : Started application in 0.534 seconds (JVM running for 1287.532) 
2016-06-26 12:44:13.066 INFO 1187 --- [nio-8093-exec-3] s.c.a.AnnotationConfigApplicationContext : Closing org.spring[email protected]f738b82: startup date [Sun Jun 26 12:44:13 CST 2016]; parent: org.spring[email protected]2757ca3e 
2016-06-26 12:44:13.066 INFO 1187 --- [nio-8093-exec-3] s.c.a.AnnotationConfigApplicationContext : Closing org.spring[email protected]2757ca3e: startup date [Sun Jun 26 12:44:12 CST 2016]; root of context hierarchy 
2016-06-26 12:44:13.103 DEBUG 1187 --- [nio-8093-exec-3] o.s.c.c.discovery.HeartbeatProperties : Computed heartbeatInterval: PT20S 

Aber nach allen Operationen wurde der Wert von "Nachricht" nicht entsprechend geändert. Könnte jemand bitte für den Fall helfen?

Antwort

3

Die Konfig-Werte müssen in einem @ConfigurationProperties Objekt sein oder Ihre Klasse muss mit @RefreshScope kommentiert werden.

+0

Es hilft mir. Danke vielmals. –