Loading dynamic externalized property files - spring

This is a spring 2.5 based project. I need to load a externalized property file when
application server starts up.I am shipping my solution to 10 users.(10 Jboss instances) where
each connect to their own database schema. Each user has a client id value saved in the
database. This will be the name of the externalized property file. If the property file name is fixed I could
load as below
<context:property-placeholder
location="classpath:/tmp/client001.properties" />
please help to find a approach how to load this when name of the property file (client001) is in the
database.
Loading dynamic externalized property files

You could take the name of the file from a system variable, loaded with the corresponding value on each server.
Take a look at this question.
Spring: Injecting different properties file according to profile

Related

how to load custom properties in application.properties

In spring boot , there is an property file application.property, along with this property , I have created an extra property file named myownprop.properties.
How can I load myownprop.properties in application.property? means how to include another named properties in application.properties?
any update ?
You could use the spring.config.additional-location property as described here: https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html#boot-features-external-config-application-property-files. It allows you to add additional files without messing with the nice default hierarchy of property sources that Spring Boot defines.
You could add a new active profile in your current application.properties
spring:
profiles:
active: dev, additional
and then add a new application-additional.properties file in your resource folder. The entries within the new file are then available as they are in the application.properties.

Is it possible to reference a specific property from spring boot application.properties in an external property file

In spring boot I have an application.properties file in which I have a property
apple = X.
I have another custom property file Custom.properties. I want to reference apple in this custom property file so I have this:
orange = ${spring.apple}.
But this does not work at runtime.
Is there any way to get access to an application.properties property from another custom properties file?
Edit:
I also tried orange=${apple}, that does not work either. I set spring.config.location to point to the directory that has application.properties and my custom.properties file also. I assumed spring boot would load any properties files it sees in spring.config.location but looks like it does not.
Is there any way to load my custom.properties file in addition to application.properties?

Spring boot, use profiles to load files

I have used spring-boot profiles to change property values for different environments, now I want to use the same approach to load different resource files, ie example I have dev_queries and prod_queries.xml with sql queries.
How can I make spring-boot load dev_queries.xml if active profile is dev and prod_queries.xml otherwise. I know that I can check the active profile but my idea is to do not add specific logic for handle this situation.
Would it help to externalize the filename as a custom property (docs, especially 24.4)? So that in your properties you would use:
# application-dev.properties
myapp.query-source=dev_queries.xml
# application-production.properties
myapp.query-source=prod_queries.xml
In your application beans this setting can be accessed by using the #Value annotation:
#Value("${myapp.query-source}")
private String querySource; // will be dev_queries.xml or prod_queries.xml
That way in the code where you are loading the xml file you don't have to conditionally check for the currently active profiles but can externalize that setting to the properties.

How do I access Spring properties in a logback configuration

Is there a way to access Spring properties within a logback.xml file?
I know one can import a properties file if you know its location, but I'm using Spring profiles to control where the properties file should be loaded or not.
Is there done kind of connector that asked me to feed Spring data into logback? This would only be at startup; I don't need to be able to do this on the fly.
I'm guessing you do have to import a property file (common property file, non-environment specific one) that will contain the name of the property that you are going to use in the logback.xml, and that you want to optionally override the value of the property for some environment (you need at least one property file containing the name of the property, because you will be using that property in the logback.xml, and you need it to be available to be able to use it).
For the optional environment-override, how about including an additional property file? For example, we use both application.properties and application-${spring.profiles.active}.properties files. Then if we don't need to override the property for some environment, we simply don't include it in the environment specific property file (application-dev.properties, etc.)

How can I change the value for application.properties dynamically?

How can I change the value for application-properties.xml file dynamically through the program in the spring hibernate framework. Actually Iam using config-mysql.xml for connecting database. In that I want to change the database name dynamically at runtime. for example in that file having jdbc:mysql://localhost:3306/usermgmt . now I want to change the usermgmt value at dynamically.Thanks in advance.

Resources