Я учусь spring-cloud-config
, и я хотел бы использовать разные профили, но я всегда получаю значения из профиля default
.
У меня есть два файла свойств в репозитории git и файл с *Суффикс 1005 * переопределяет ключ из профиля default
:
- image-service.properties
- image-service-prod.properties
Кажетсячто мой конфиг-сервер работает нормально:
GET http://localhost:8888/image-service/default:
{"name":"image-service","profiles":["default"],"label":null,"version":"fb78fe4429a33c266d6eb07a9e482b8fd264dd7c","state":null,"propertySources":
[{"name":"https://bitbucket.org/.../...-configuration.git/image-service.properties","source":{"service.image.hello":"image-common"}}]}
GET http://localhost:8888/image-service/prod
{"name":"image-service","profiles":["prod"],"label":null,"version":"fb78fe4429a33c266d6eb07a9e482b8fd264dd7c","state":null,"propertySources":
[{"name":"https://bitbucket.org/.../...-configuration.git/image-service-prod.properties","source":{"service.image.hello":"image-prod"}},
{"name":"https://bitbucket.org/.../...-configuration.git/image-service.properties","source":{"service.image.hello":"image-common"}}]}
Я активировал prod
профиль в моем приложении REST, но всегда отображается значение из профиля по умолчанию.
application.properties клиентского приложения:
server.port=8889
spring.application.name=image-service
spring.cloud.config.uri=http://localhost:8888
spring.profiles.active=prod
REST контроллерклиентское приложение:
@RefreshScope
@RestController
public class EchoController {
@Value("${service.image.hello}")
private String hello;
@RequestMapping("/show")
@ResponseBody
public String showConfig() {
return new StringBuilder()
.append("image-service: ").append(hello)
.toString();
}
}
Результат:
image-service: image-common
Журнал из клиентского приложения:
c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://localhost:8888
c.c.c.ConfigServicePropertySourceLocator : Located environment: name=image-service, profiles=[default], label=null, version=fb78fe4429a33c266d6eb07a9e482b8fd264dd7c, state=null
b.c.PropertySourceBootstrapConfiguration : Located property source: CompositePropertySource {name='configService', propertySources=[MapPropertySource {name='configClient'}, MapPropertySource {name='https://bitbucket.org/.../...-configuration.git/image-service.properties'}]}
c.r.d.springconfig.client.Application : The following profiles are active: prod
ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@7ccdc9e7: startup date [Sun Sep 23 22:31:55 CEST 2018]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@7fd618b5
o.s.cloud.context.scope.GenericScope : BeanFactory id=51790958-c0a2-3d61-91d6-a8dcd5395c7e
trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$bf37cae6] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8889 (http)
Кажется, ячто-то пропустил, но я не вижу, что.