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

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.

Related

Mule Expression component not able to fetch value from properties file

I want to fetch values dynamically from properties so I have implemented one poc. In that poc I have declared one object with value in mule expression component. After that I am fetching the value key from properties file. It is showing exceptions while testing the application.
Exception MSG: Root Exception stack trace: unresolvable property or identifier: $
EX-1:
flowVars.deptCode=21432143;
property3=${flowVars.deptCode};
EX-2:
property3=${21432143};
In the above two examples ex-2 has worked fine and ex-1 has failed .
Please let me know if anyone have clarity on that.
Thanks,
Praveen
Mule is using Spring Properties which can be kept in a seperate properties file and then retrieved/used in your application via ${propertyName}.
A property placeholder is used to define where you keep those properties.
Ex 1 is not possible because properties are not aware at all of any variables or properties inside of your Mule application.
Another issue is that those files will be loaded when the application is started.
If you change the value of a property a restart of your application is needed, so your approach isn't going to work.
More info in the docs here:
https://docs.mulesoft.com/mule-user-guide/v/3.8/configuring-properties
You can use dataweave script to dynamically read values from property file
#[dw("p(flowVars.deptCode)")]

Spring with Hibernate- how to pass schema name dynamically

I am using spring-Hibernate DAO Layer, i have created spring configuration file having data source and all the hbm xml list and each hbm is mapped with the table as
table ="schema1.table1"
We have another schema say prodSchema in production, i want to know how to pass schema name dynamically by using propfile etc.to the hbm file so that in runtime i can change.
Java annotation only supports compile time constants. i.e. you cannot put variable in annotation parameter.
REf : http://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.28
Your situation is common to most of the project and developer. I generally use external database configuration file, where I put the connection parameters, schema and credentials. This file is created on each environment once and remains unchanged until there is any change in DB server.
General Hibernate Property for quick reference.
hibernate.connection.driver_class : JDBC driver class
hibernate.connection.url : JDBC URL (may contain schema)
hibernate.connection.username : database user
hibernate.connection.password : database user password
hibernate.default_schema : Qualify unqualified table names with the
given schema/tablespace in generated SQL. e.g. SCHEMA_NAME (use this
if you don't specify in JDBC URL)

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.)

Getting Laravel Workbench Package Config Values From Within ServiceProvider Registration

Within MymoduleServiceProvider->register(),
I want to be able to pull configuration values from the same package.
However whenever I
var_dump($app['config']['file.option']
I get a null value
I know that the file structure is correct because if I do:
Config::get('package::file.option');
from a controller, I get the correct value
How can I load my packages configuration values from within the ServiceProvider->register() method?
$app['config'] is an instance of Config stored in the IOC container.
So try using the get() method directly from the IOC container like so:
$app['config']->get('package::file.option');
as an equivalent to using the facade
\Config::get('package::file.option');

Loading dynamic externalized property files

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

Resources