Issue
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.
Solution
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
Answered By - B. Othmane
Answer Checked By - Terry (JavaFixing Volunteer)