Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Cloud Config Client: Fetching config from wrong server

When I run my Spring Cloud Config Client project config-client, I found these error:

2018-02-09 10:31:09.885  INFO 13933 --- [           main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at: http://localhost:8888
2018-02-09 10:31:10.022  WARN 13933 --- [           main] c.c.c.ConfigServicePropertySourceLocator : Could not locate PropertySource: I/O error on GET request for "http://localhost:8888/config-client/dev/master": 拒绝连接 (Connection refused); nested exception is java.net.ConnectException: 拒绝连接 (Connection refused)
2018-02-09 10:31:10.026  INFO 13933 --- [           main] c.y.c.ConfigClientApplication            : No active profile set, falling back to default profiles: default
2018-02-09 10:31:10.040  INFO 13933 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@33b1c5c5: startup date [Fri Feb 09 10:31:10 CST 2018]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@1ffe63b9
2018-02-09 10:31:10.419  INFO 13933 --- [           main] o.s.cloud.context.scope.GenericScope     : BeanFactory id=65226c2b-524f-3b14-8e17-9fdbc9f72d85
2018-02-09 10:31:10.471  INFO 13933 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$25380e89] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-02-09 10:31:10.688  INFO 13933 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 10001 (http)
2018-02-09 10:31:10.697  INFO 13933 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2018-02-09 10:31:10.698  INFO 13933 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.27
2018-02-09 10:31:10.767  INFO 13933 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2018-02-09 10:31:10.768  INFO 13933 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 727 ms
2018-02-09 10:31:10.861  INFO 13933 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Mapping servlet: 'dispatcherServlet' to [/]
2018-02-09 10:31:10.864  INFO 13933 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-02-09 10:31:10.864  INFO 13933 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2018-02-09 10:31:10.864  INFO 13933 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2018-02-09 10:31:10.865  INFO 13933 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
2018-02-09 10:31:10.895  WARN 13933 --- [           main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'configClientApplication': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'content' in value "${content}"
2018-02-09 10:31:10.896  INFO 13933 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2018-02-09 10:31:10.914  INFO 13933 --- [           main] utoConfigurationReportLoggingInitializer : 

Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled. 2018-02-09 10:31:10.923 ERROR 13933 --- [ main] o.s.boot.SpringApplication : Application startup failed

Apparently, the config server is wrong. However, the Spring Cloud Config Server is running at localhost:10000/ and application.yml of the project(config-client) is below. Why the spring.cloud.config.uri doesn't work?

application.yml [config-client]

server:
  port: 10001
spring:
  application:
    name: config-client
  cloud:
    config:
      label: master
      profile: dev
      uri: http://localhost:10000
like image 394
wenxiong yan Avatar asked Feb 09 '18 03:02

wenxiong yan


People also ask

What is springspring cloud config client?

Spring Cloud Config Client is also a Spring Boot application. So if you do not have one, follow this tutorial to learn how to create a very simple Spring Boot application using Spring Initializr.

How do I name a Spring Cloud config server property file?

Properties files served by Spring Cloud Config Server can be names in few different ways: {microservice-application-name}.properties – if a property file which is stored in Git repo is named after the Microservice name, then properties loaded from this file will have a higher priority.

Why is the config client not fetching properties from other URLs?

For example, if the Config Server returns a 500 (Internal Server Error) response or the Config Client receives a 401 from the Config Server (due to bad credentials or other causes), the Config Client does not try to fetch properties from other URLs. An error of that kind indicates a user issue rather than an availability problem.

How do I connect to a config server in Spring Boot?

In the application.properties file, add the following property. spring.config.import=optional:configserver:http://localhost:8012. This will let your application connect to the Config Server and fetch configuration properties. Removing the optional: prefix will cause the Config Client to fail if it is unable to connect to Config Server.


2 Answers

Fur future readers, as answered here, when using Spring Cloud Config Server, we should specify basic bootstrap settings such as : spring.application.name and spring.cloud.config.uri inside bootstrap.yml (or "bootstrap.properties").

Upon startup, Spring Cloud makes an HTTP call to the config server with the name of the application and retrieves back that application's configuration.

That's said, since we're externalizing our settings using Spring Cloud Config Server, any default configurations defined in application.yml (or "application.properties") will be overridden during the bootstrap process upon startup.

like image 121
Omar Avatar answered Oct 14 '22 08:10

Omar


IntelliJ Users: add the following override parameter in the run/Debug Configuration:

Name: spring.cloud.config.uri

Value: http://your-server-here/config-server

like image 32
jamesioppolo Avatar answered Oct 14 '22 06:10

jamesioppolo