Can a Library jar read properties from Spring Cloud Config Server? - spring

I have a shared Library that needs some properties from a .properties file. This shared Library will be used by a Spring Boot application. We already have a Spring Cloud Config server which is serving the properties to this Spring Boot application.
Now, we want the properties for the Library also to be fetched from the Config Server, rather than packaging it's properties file along with the library jar file.
Can I let my Library file pick-up properties from the Spring Cloud Config server ? The Spring Cloud Config server documentation states the following.. seeing it, looks like only a 'Spring Boot' application can talk to the Spring Cloud Config Server to fetch properties from there.
Any pointers or suggestions ?
can be used with any application running in any language
To use these features in an application, just build it as a Spring
Boot application that depends on spring-cloud-config-client
Ref: http://cloud.spring.io/spring-cloud-config/spring-cloud-config.html#_spring_cloud_config_client

No, a Library cannot talk to the Spring Cloud Config Server to get the properties file. Instead the config server should have those Library file's properties define din the using application's properties file.
Library: x.jar
Application: y.jar
Property file in Config Server: y.properties / y.yml
This property file will have the properties for classes present both in x.jar and in y.jar

Related

Spring cloud config server not honoring logging.file property and not logging external file

I'm using spring-boot-starter 2.3.3.RELEASE version. I'm running my spring cloud configuration server in native profile (looking for configuration files in file system). I added
logging.file = /var/log/config.log in application.properties file. But my application is not logging logs to this file.(All other microservices are logging to this location). Am I missing any additional settings for Spring cloud config server? Thank you so much for your help.
In the spring boot 2.3.3 RELEASE documentation the logging properties that specify where the location should be is indicated using the property:
logging.file.path={path}
The documentation:
https://docs.spring.io/spring-boot/docs/2.3.3.RELEASE/reference/htmlsingle/#boot-features-logging-file-output
This modification from logging.path to logging.file.path appears as a deprecation in Spring Boot 2.2:
https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.2-Release-Notes#deprecations-in-spring-boot-22
One way to do it with spring-boot application is, setting it from command line argument as default it will dump every thing on console.
logging.file=logs/test.log
Old school but far effective, save path in application.properties
logging.file=logs/test.log

Load Logback config from the library in Spring Boot application

I'm trying to build a logging library which will be used across my services. I would like it to come with a default Logback configuration (predefined appenders). Is there a way to tell the application to load that config when the library is added to the project?
Ideally i would like to have this in the library, in application.yml
logging:
config: classpath:logback.xml
Application should use that configuration, and also allow to load custom application Logback config if developer wants to override the one.

Passing configuration from yaml file to spring boot application without rebuilding it

How to pass configuration through yaml file to a running spring boot application so that there is no need of rebuilding the application and changes are reflected while the application is runnig?
I think this can help you:
How to hot-reload properties in Java EE and Spring Boot?
Take a look at Spring Boot Cloud Config. It allows you to manage your config files centralized and has the ability to push new configurations to the connected applications.

Separate properties for a shared spring library contained inside a spring boot application

I created a shared library in spring that I deploy as an artifact in an artifactory. I use this shared library artifact in another spring boot application as a pom dependency. Shared library has it's own properties files under src/main/resources
I am having problems with the following:
When I try to load the spring boot application, it is not able to load the properties for the shared library and expects all the properties shared library needs in the outer spring boot application. How can fix this and have shared library always read its own properties file ?
Use #PropertySource annotation to provide the two sources for your app:
#PropertySources({
#PropertySource("classpath:yourSharedLib.properties"),
#PropertySource("classpath:youApp.properties")
})

Spring Boot Micro-service fails Kerberos Authentication when deployed on Pivotal Cloud Foundry Platform

We have developed a Spring Boot Application to query data from Hbase on HDP 2.5.
The application works fine when we run it on our local windows machines as it is able to find the jaas.conf & krb5.conf file which have been kept under resources folder of the application and we have provided them as system properties in our code as e.g.
System.setProperties("javax.security.auth.useSubjectCredsOnly","false");
System.setProperty("java.security.krb5.conf","D:\\host\\workspace\\projectname\\src\\main\\resources\\krb5.conf");
However when we deploy in PCF it is unable to read those file which are set as system properties.
Question
What is the way to set environment variables in PCF ?
How do we place files in PCF so that they are available to the classpath of an application ?
You can specify an environment variable in your deployment manifest file.
Here are the details.
This is assuming your jar file was packaged with krb5.conf file.
The other option is to use Config Server. Here is an introduction on Spring Cloud Config

Resources