Reputation: 33
I am writing a Spring Boot Application. This application talks to a Main Frame through MessageQueues
So inorder to talk to that MainFrame we are provided with a java jar(which has the code that talks to MessageQueues ). lets call it proxy jar.
We have to use the operations written from the above mentioned proxy jar . We dont write any code to read/write to MessageQueues (IBM MessageQueues) in our application, this is done by the proxy jar and its dependent runtime jar.
So here comes the problem, this Proxy jar is coded in such a way that it looks for a file called 'commcfg.properties' in the classpath (expects the name to be exactly same). Actually the Proxy jar uses another dependent jar (lets call runtime jar)which reads the queue details from commcfg.properties and reads/writes from Message Queues.
commcfg.properties have the values of MessageQueue and Host and port of those Queues . In short Queue details.
So the trouble is these MessageQueue details will be different in different environments. I need to use the commcfg.properties according to environment
So far my trials to solve this.
Lets say I have two environments . So I will have two different set of values of commcfg.properties
I have created files as follows commcfg.DEV.properties commcfg.PROD.properties so that they will be in classpath
Next I have written code such that it will pick up the particular property file depending on Environment and rename it to commcfg.properties(as the Proxy jar and its helper dependent Runtime jar need the exact name to be commcfg.properties).
In my local workspace I could do this . But when deployed (we use docker) that gets packaged into spring boot jar.
So my hack is not working as we cannot rename files with in jars.
Another thought I had:
Before I call my functionality code , I will put the commcfg.properties in class path (project/src/main/resources) I will read it and modify the values as needed per environment. The values I will have them in application.properties. But again I doubt that with in jar I cannot modify the file.
Hoping I am clear Kindly help me out..
Upvotes: 2
Views: 5584
Reputation: 1
you can put the properties files on the same path of spring-boot jar, the config items can override the properties in the jar.
Upvotes: 0
Reputation: 1413
In spring boot, You can register your properties file with a Java annotation @PropertySource
@SpringBootApplication
@PropertySource("classpath:commcfg.properties")
public class ApplicationConfig
{
public static void main(String args[])
{
SpringApplication.run(ApplicationConfig.class);
}
}
and let the commcfg.properties file contain the DEV environment details
messageQueue.name=myMessageQueue
messageQueue.host=host
messageQueue.port=4040
Now build your jar file and you get yourjar.jar
Now run it in DEV environment with default values
java -jar yourjar.jar
run it in QA environment with overriding the default values in your config file
java -jar --messageQueue.name=diffrenthost --messageQueue.host=diffrenthost --messsageQueue.port=diffrentport yourjar.jar
This way you can override your default values. I hope this helps
Upvotes: 2