hell_storm2004
hell_storm2004

Reputation: 1605

propertySources Shows Empty (Spring Cloud Config)

I am trying to learn Spring Cloud. So I created a new project using Spring Starter (a very basic one)

I configured my application.properties like so:

server.port=9090
spring.cloud.config.server.native.searchLocations=file://H:/opt/app/app.static.properties
spring.profiles.active=native

But when I start my Spring Boot application, it starts fine (from what I can say), but when I hit URL http://localhost:9090/config/default/master

I get the output on the browser:

{"name":"config","profiles":["default"],"label":"master","version":null,"state":null,"propertySources":[]}

My Console output is:

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
[32m :: Spring Boot :: [39m              [2m (v2.5.2)[0;39m

[2m2021-07-09 20:28:59.573[0;39m [32m INFO[0;39m [35m30936[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36mcom.example.demo.DemoApplication        [0;39m [2m:[0;39m Starting DemoApplication using Java 1.8.0_281 on HVDIVD17CA50359 with PID 30936 (H:\git\develop\demo\target\classes started by sm187t in H:\git\develop\demo)
[2m2021-07-09 20:28:59.583[0;39m [32m INFO[0;39m [35m30936[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36mcom.example.demo.DemoApplication        [0;39m [2m:[0;39m The following profiles are active: native
[2m2021-07-09 20:28:59.909[0;39m [32m INFO[0;39m [35m30936[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36m.e.DevToolsPropertyDefaultsPostProcessor[0;39m [2m:[0;39m Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
[2m2021-07-09 20:29:06.725[0;39m [32m INFO[0;39m [35m30936[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36mo.s.cloud.context.scope.GenericScope    [0;39m [2m:[0;39m BeanFactory id=374f6c33-f58f-370c-bb56-bdf932b163cb
[2m2021-07-09 20:29:09.167[0;39m [32m INFO[0;39m [35m30936[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36mo.s.b.w.embedded.tomcat.TomcatWebServer [0;39m [2m:[0;39m Tomcat initialized with port(s): 9090 (http)
[2m2021-07-09 20:29:09.204[0;39m [32m INFO[0;39m [35m30936[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36mo.apache.catalina.core.StandardService  [0;39m [2m:[0;39m Starting service [Tomcat]
[2m2021-07-09 20:29:09.204[0;39m [32m INFO[0;39m [35m30936[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36morg.apache.catalina.core.StandardEngine [0;39m [2m:[0;39m Starting Servlet engine: [Apache Tomcat/9.0.48]
[2m2021-07-09 20:29:09.677[0;39m [32m INFO[0;39m [35m30936[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36mo.a.c.c.C.[Tomcat].[localhost].[/]      [0;39m [2m:[0;39m Initializing Spring embedded WebApplicationContext
[2m2021-07-09 20:29:09.678[0;39m [32m INFO[0;39m [35m30936[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36mw.s.c.ServletWebServerApplicationContext[0;39m [2m:[0;39m Root WebApplicationContext: initialization completed in 9764 ms
[2m2021-07-09 20:29:10.197[0;39m [32mDEBUG[0;39m [35m30936[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36mo.s.b.w.s.ServletContextInitializerBeans[0;39m [2m:[0;39m Mapping filters: filterRegistrationBean urls=[/*] order=-2147483647, springSecurityFilterChain urls=[/*] order=-100, characterEncodingFilter urls=[/*] order=-2147483648, formContentFilter urls=[/*] order=-9900, requestContextFilter urls=[/*] order=-105
[2m2021-07-09 20:29:10.197[0;39m [32mDEBUG[0;39m [35m30936[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36mo.s.b.w.s.ServletContextInitializerBeans[0;39m [2m:[0;39m Mapping servlets: dispatcherServlet urls=[/]
[2m2021-07-09 20:29:11.354[0;39m [32mDEBUG[0;39m [35m30936[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36ms.w.s.m.m.a.RequestMappingHandlerAdapter[0;39m [2m:[0;39m ControllerAdvice beans: 0 @ModelAttribute, 0 @InitBinder, 1 RequestBodyAdvice, 1 ResponseBodyAdvice
[2m2021-07-09 20:29:12.124[0;39m [32mDEBUG[0;39m [35m30936[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36ms.w.s.m.m.a.RequestMappingHandlerMapping[0;39m [2m:[0;39m 23 mappings in 'requestMappingHandlerMapping'
[2m2021-07-09 20:29:12.275[0;39m [32mDEBUG[0;39m [35m30936[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36mo.s.w.s.handler.SimpleUrlHandlerMapping [0;39m [2m:[0;39m Patterns [/webjars/**, /**] in 'resourceHandlerMapping'
[2m2021-07-09 20:29:12.309[0;39m [32mDEBUG[0;39m [35m30936[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36m.m.m.a.ExceptionHandlerExceptionResolver[0;39m [2m:[0;39m ControllerAdvice beans: 0 @ExceptionHandler, 1 ResponseBodyAdvice
[2m2021-07-09 20:29:13.756[0;39m [32m INFO[0;39m [35m30936[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36mo.s.b.a.e.web.EndpointLinksResolver     [0;39m [2m:[0;39m Exposing 1 endpoint(s) beneath base path '/actuator'
[2m2021-07-09 20:29:13.787[0;39m [32m INFO[0;39m [35m30936[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36mo.s.s.web.DefaultSecurityFilterChain    [0;39m [2m:[0;39m Will secure any request with [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@33b379d5, org.springframework.security.web.context.SecurityContextPersistenceFilter@701d0f6c, org.springframework.security.web.header.HeaderWriterFilter@255f44df, org.springframework.web.filter.CorsFilter@32abf174, org.springframework.security.web.csrf.CsrfFilter@5019771a, org.springframework.security.web.authentication.logout.LogoutFilter@74f8b524, org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter@2364f95a, org.springframework.security.web.authentication.ui.DefaultLoginPageGeneratingFilter@53fb9109, org.springframework.security.web.authentication.ui.DefaultLogoutPageGeneratingFilter@64e99fc9, org.springframework.security.web.authentication.www.BasicAuthenticationFilter@54704c84, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@334cbd88, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@7e74ddeb, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@6033bddc, org.springframework.security.web.session.SessionManagementFilter@1b3eed50, org.springframework.security.web.access.ExceptionTranslationFilter@4d7a1b8f, org.springframework.security.web.access.intercept.FilterSecurityInterceptor@4590bbf6]
[2m2021-07-09 20:29:14.137[0;39m [32m INFO[0;39m [35m30936[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36mo.s.b.d.a.OptionalLiveReloadServer      [0;39m [2m:[0;39m LiveReload server is running on port 35729
[2m2021-07-09 20:29:15.000[0;39m [32m INFO[0;39m [35m30936[0;39m [2m---[0;39m [2m[on(3)-127.0.0.1][0;39m [36mo.a.c.c.C.[Tomcat].[localhost].[/]      [0;39m [2m:[0;39m Initializing Spring DispatcherServlet 'dispatcherServlet'
[2m2021-07-09 20:29:15.001[0;39m [32m INFO[0;39m [35m30936[0;39m [2m---[0;39m [2m[on(3)-127.0.0.1][0;39m [36mo.s.web.servlet.DispatcherServlet       [0;39m [2m:[0;39m Initializing Servlet 'dispatcherServlet'
[2m2021-07-09 20:29:15.002[0;39m [32mDEBUG[0;39m [35m30936[0;39m [2m---[0;39m [2m[on(3)-127.0.0.1][0;39m [36mo.s.web.servlet.DispatcherServlet       [0;39m [2m:[0;39m Detected StandardServletMultipartResolver
[2m2021-07-09 20:29:15.002[0;39m [32mDEBUG[0;39m [35m30936[0;39m [2m---[0;39m [2m[on(3)-127.0.0.1][0;39m [36mo.s.web.servlet.DispatcherServlet       [0;39m [2m:[0;39m Detected AcceptHeaderLocaleResolver
[2m2021-07-09 20:29:15.002[0;39m [32mDEBUG[0;39m [35m30936[0;39m [2m---[0;39m [2m[on(3)-127.0.0.1][0;39m [36mo.s.web.servlet.DispatcherServlet       [0;39m [2m:[0;39m Detected FixedThemeResolver
[2m2021-07-09 20:29:15.007[0;39m [32mDEBUG[0;39m [35m30936[0;39m [2m---[0;39m [2m[on(3)-127.0.0.1][0;39m [36mo.s.web.servlet.DispatcherServlet       [0;39m [2m:[0;39m Detected org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator@611461
[2m2021-07-09 20:29:15.008[0;39m [32mDEBUG[0;39m [35m30936[0;39m [2m---[0;39m [2m[on(3)-127.0.0.1][0;39m [36mo.s.web.servlet.DispatcherServlet       [0;39m [2m:[0;39m Detected org.springframework.web.servlet.support.SessionFlashMapManager@7077db3
[2m2021-07-09 20:29:15.008[0;39m [32mDEBUG[0;39m [35m30936[0;39m [2m---[0;39m [2m[on(3)-127.0.0.1][0;39m [36mo.s.web.servlet.DispatcherServlet       [0;39m [2m:[0;39m enableLoggingRequestDetails='false': request parameters and headers will be masked to prevent unsafe logging of potentially sensitive data
[2m2021-07-09 20:29:15.009[0;39m [32m INFO[0;39m [35m30936[0;39m [2m---[0;39m [2m[on(3)-127.0.0.1][0;39m [36mo.s.web.servlet.DispatcherServlet       [0;39m [2m:[0;39m Completed initialization in 8 ms
[2m2021-07-09 20:29:15.888[0;39m [32m INFO[0;39m [35m30936[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36mo.s.b.w.embedded.tomcat.TomcatWebServer [0;39m [2m:[0;39m Tomcat started on port(s): 9090 (http) with context path ''
[2m2021-07-09 20:29:16.252[0;39m [32m INFO[0;39m [35m30936[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36mcom.example.demo.DemoApplication        [0;39m [2m:[0;39m Started DemoApplication in 19.628 seconds (JVM running for 24.074)
[2m2021-07-09 20:29:30.465[0;39m [32mDEBUG[0;39m [35m30936[0;39m [2m---[0;39m [2m[nio-9090-exec-1][0;39m [36ms.w.s.m.m.a.RequestMappingHandlerMapping[0;39m [2m:[0;39m Mapped to org.springframework.cloud.config.server.environment.EnvironmentController#labelled(String, String, String)
[2m2021-07-09 20:29:30.522[0;39m [32mDEBUG[0;39m [35m30936[0;39m [2m---[0;39m [2m[nio-9090-exec-1][0;39m [36mo.s.web.servlet.DispatcherServlet       [0;39m [2m:[0;39m GET "/config/default/master", parameters={}
[2m2021-07-09 20:29:30.526[0;39m [32mDEBUG[0;39m [35m30936[0;39m [2m---[0;39m [2m[nio-9090-exec-1][0;39m [36ms.w.s.m.m.a.RequestMappingHandlerMapping[0;39m [2m:[0;39m Mapped to org.springframework.cloud.config.server.environment.EnvironmentController#labelled(String, String, String)
[2m2021-07-09 20:29:30.994[0;39m [32mDEBUG[0;39m [35m30936[0;39m [2m---[0;39m [2m[nio-9090-exec-1][0;39m [36mm.m.a.RequestResponseBodyMethodProcessor[0;39m [2m:[0;39m Using 'application/json;q=0.8', given [text/html, application/xhtml+xml, image/avif, image/webp, image/apng, application/xml;q=0.9, application/signed-exchange;v=b3;q=0.9, */*;q=0.8] and supported [application/json]
[2m2021-07-09 20:29:31.004[0;39m [32mDEBUG[0;39m [35m30936[0;39m [2m---[0;39m [2m[nio-9090-exec-1][0;39m [36mm.m.a.RequestResponseBodyMethodProcessor[0;39m [2m:[0;39m Writing [Environment [name=config, profiles=[default], label=master, propertySources=[], version=null, state= (truncated)...]
[2m2021-07-09 20:29:31.063[0;39m [32mDEBUG[0;39m [35m30936[0;39m [2m---[0;39m [2m[nio-9090-exec-1][0;39m [36mo.s.web.servlet.DispatcherServlet       [0;39m [2m:[0;39m Completed 200 OK

Shouldn't the propertySources be full of the property file entries? I am new to this. So mostly learning from tutorials and guides. Is my understanding correct?

Any help would be appreciated. Thanks.

Upvotes: 2

Views: 4706

Answers (6)

sagar waghmare
sagar waghmare

Reputation: 1

It is usually a problem of file name or file path location. It was not working in my case because of the file name. I extended my file name to -dev and added it to the URL. It worked.

Upvotes: 0

DEVANAND
DEVANAND

Reputation: 1

if you are using notepad, remove .txt and save the file as .properties file

Upvotes: 0

MP123
MP123

Reputation: 1

Try adding prop spring.cloud.config.server.git.searchPaths. This will tell spring in which path your property files are.

spring.profiles.active=git
spring.cloud.config.server.git.uri=https://gitlab.com/<project-name>/<app-name>.git
spring.cloud.config.server.git.clone-on-start=true
spring.cloud.config.server.git.default-label=main
spring.cloud.config.server.git.username=git-username
spring.cloud.config.server.git.password=your-access-token-from-git
spring.cloud.config.server.git.searchPaths=path*

Upvotes: 0

Utkarsh
Utkarsh

Reputation: 11

If you created the file using a notepad, it will put the extension of the file like limits-service.properties.txt , instead you need the file name limits-service.properties . I tried renaming the file from CMD and it worked .

rename limits-service.properties.txt to limits-service.properties

Upvotes: 1

ramya
ramya

Reputation: 1

I got the same error followed the below steps.

Application properties is as below:

spring.application.name=spring-cloud-config-server
server.port=8888
logging.level.web=DEBUG
spring.cloud.config.server.git.uri=file:///C:/Users/DELL/git-localconfig-repo

Added dependency:

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency> 

In limits-service pom.xml file

If it still does not work, try to delete limits-service.properties and create a new one, or else try creating limits-service-dev.properties, limits-service-prod.properties and call them by URLs http://localhost:8888/limits-service/dev and check if those work ..

Issue is mostly i guess with path or file name.

Upvotes: 0

B. Othmane
B. Othmane

Reputation: 66

The searchLocations property accepts a location of files and/or sub-directories. try spring.cloud.config.server.native.searchLocations=file://H:/opt/app/ instead of spring.cloud.config.server.native.searchLocations=file://H:/opt/app/app.static.properties and hit http://localhost:9090/config/default/master/app.static.properties

Upvotes: 5

Related Questions