简体   繁体   English

Spring Cloud Config Server无法解析占位符

[英]Spring Cloud Config Server Could not resolve placeholder

I have added spring-cloud-config-server to my stack in the hope of having different sets of config loaded for different spring profiles (namely development, staging and production). 我将spring-cloud-config-server添加到我的堆栈中,希望为不同的spring配置文件(即开发,暂存和生产)加载不同的配置集。

My config server app starts on port 8888, fetches config directly from a private gitlab repository and has security. 我的配置服务器应用程序从端口8888开始,直接从私有gitlab存储库中获取配置,并且具有安全性。 I tested this by hitting it manually and checking that the correct properties are returning. 我通过手动点击并检查是否返回了正确的属性来进行测试。 So far so good. 到现在为止还挺好。

I will have several 'client' apps that I want to consume the properties from my config server but for now I'm just trying with one. 我将有几个“客户端”应用程序,我想使用配置服务器中的属性,但现在我只尝试其中一个。 To test it out, I've put a 为了测试,我已经放了一个

@Value("${some.property}")
private string someProperty;

in one of my web resources in the client app. 在客户端应用程序中的我的网络资源之一中。 This property is not in any of the client app's property files (wondering if this may be the issue - but it seems restrictive if it is). 此属性不在客户端应用程序的任何属性文件中(这可能是个问题,这很奇怪-但如果存在问题,则似乎是限制性的)。

I've also pointed the client app at the config server. 我也已将客户端应用程序指向配置服务器。 The config for both apps both config server and client app are in their bootstrap.properties files to ensure they're loaded early in the process. 配置服务器和客户端应用程序的配置都位于其bootstrap.properties文件中,以确保它们在此过程的早期加载。

In fact my two apps are containerised in Docker images and they are brought up by a docker-compose.yml file. 实际上,我的两个应用程序都在Docker映像中进行了容器化,并由docker-compose.yml文件启动。 I've actually got it set up to that the client app waits for the config server to be running before starting up. 我实际上已经将其设置为客户端应用程序在启动之前等待配置服务器运行。

During the client app's startup, I can see it fetching config from the config server: 在客户端应用程序启动期间,我可以看到它从配置服务器获取配置:

| 20:12:50.692 [main] INFO  o.s.c.c.c.ConfigServicePropertySourceLocator.getRemoteEnvironment 205 - Fetching config from server at : http://config-server:8888

and it appears to be successful with a 205. 205似乎很成功。

However, the client app startup then fails: 但是,客户端应用程序启动失败:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'exampleResource': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'some.property' in value "${some.property}"

I have the active profile set to 'development' in the client app. 我在客户端应用程序中将活动配置文件设置为“开发”。 The properties files on the config server are named: 配置服务器上的属性文件名为:

myapp-development.properties
myapp-staging.properties
myapp-production.properties

My hope is of course that the client app fetches the config from the server (which I can see happen) and then that property is available to the client app as it starts up but this does not appear to be the case. 我当然希望客户端应用程序从服务器获取配置(我可以看到这种情况),然后该属性在启动时可供客户端应用程序使用,但事实并非如此。 Is it as simple as specifying a default in the value annotation? 它像在值注释中指定默认值一样简单吗? Or am I overlooking something more fundamental? 还是我忽略了更基本的东西? I followed this guide fwiw and my config server is pointing to a git repository as I mentioned above: 我按照本指南的说明进行操作,并且我的配置服务器指向上面提到的git存储库:

http://www.baeldung.com/spring-cloud-configuration http://www.baeldung.com/spring-cloud-configuration

Thanks in advance. 提前致谢。

You set credentials incorrectly in the client side app. 您在客户端应用程序中错误地设置了凭据。

It should be 它应该是

spring.cloud.config.username=myConfigServerUserName
spring.cloud.config.password=myConfigServerPassword

instead of spring.security.user.name and spring.security.user.password (which are used in the config server app). 而不是spring.security.user.namespring.security.user.password (在配置服务器应用程序中使用)。

See: http://cloud.spring.io/spring-cloud-static/spring-cloud-config/2.0.1.RELEASE/single/spring-cloud-config.html#_security_2 参见: http : //cloud.spring.io/spring-cloud-static/spring-cloud-config/2.0.1.RELEASE/single/spring-cloud-config.html#_security_2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM