Issue with spring cloud config property file order - spring-cloud

I am using spring cloud config for loading properties file for my application. I have multiple environments. I notice that the property files are loaded in wrong order. This is what i see in my logs
Located property source: CompositePropertySource [name='configService', propertySources=[MapPropertySource [name='https://github.com/xyz/configrepo.git/gatekeeper-dev.properties'], MapPropertySource [name='https://github.com/xyz/configrepo.git/gatekeeper.properties']]]
It seems that the environment specific property file is loaded first and overridden by the default property file. Is there any way i can control the order in which they are loaded and processed ?

That is the expected order (for good reasons so I am surprised you found a use case where it wasn't convenient). You can't control it except by changing the names of the files and listing them in a comma separated form. For the sake of clarity: profile specific properties always override default ones. Possibly the logs have confused you.

Related

How to introduce new stream format in beanio

Is beanio can support more stream format other than csv, fixedLength, delimited, json and xml? I have created a new module from beanio to add new format, But the beanio.properties used by StreamCompiler to map the format is resides in the beanio parent project, how will I add a new format to it?
I don't know if you can extend BeanIO this way, but it would be great if this works for you.
See Section 8 of the reference documentation on how to provide your custom beanio.properties file
8.0. Configuration
In some cases, BeanIO behavior can be controlled by setting optional property values. Properties can be set using System properties or a property file. BeanIO will load configuration setting in the following order of priority:
System properties.
A property file named beanio.properties. The file will be looked for first in the application's working directory, and then on the classpath.
The name and location of beanio.properties can be overridden using the System property org.beanio.configuration. In the following example, configuration settings will be loaded from the file named config/settings.properties, first relative to the application's working directory, and if not found, then from the root of the application's classpath.
java -Dorg.beanio.configuration=config/settings.properties example.Main
Please let us know if you can extend the formats supported this way.

Externalize configuration Akka

I am new in Akka and I faced the problem below.
I want to externalize the configuration in my App. More specifically, I have some variables that are different per each environment. So I think that I can have specific environment variables (secrets, etc) for each environment.
But what I can do with some variables (non-secrets) which are different per each environment?
What is the difference between, dev.properties, application.conf, deploy.json files?
What is the proper way to load variables from those files?
There's a few options:
Environment variables and using the support for substitution (there is also support for having default in the file and only use the environment vars if they are set). - https://github.com/lightbend/config#optional-system-or-env-variable-overrides
System properties, if you set a system property when you start the JVM, and that system property matches a path in the config file, it overrides the setting
You can point to an alternative application.conf file using a system property - https://github.com/lightbend/config#standard-behavior
If that is not enough you could also do completely custom logic around selecting logic by programmatically creating a Config instance and passing that to the ActorSystem when you create it.
The dev.properties and deploy.json is AFAIK not related to Akka, unless something specifically done in your application.

Setting Cassandra password in reference.conf using Scala

How can an attribute be set programmatically in a reference.conf file?
For example, I am using something like this in Spring to set the attributes of the keystore:
System.setProperty("server.ssl.keyStore", "keystore.jks")
System.setProperty("server.ssl.keyStorePassword", "password123")
Same way, you can override configuration from the reference conf file using system properties, they have the highest precedence order as described here:
https://github.com/lightbend/config#standard-behavior
Please be aware you need to do it before the config is loaded by the class that uses it (via ConfigFactory.load()) and if any other class has already used ConfigFactory, then a call to ConfigFactory.invalidateCaches() will also be required, otherwise the cached value will be used.

Configure Quartz.NET through a mixture of config file and constructor

Is it possible to configure Quartz through a mixture of properties held in a config file (either quartz.properties or app.config / web.config) and also some via the StdSchedulerFactory constructor?
I would like to pass the AdoJobStore connectionstring via the constructor, as it is dynamic depending on the environment, but the rest of the settings are static so would be better placed in a config file.
I've tried passing in only the quartz.dataSource.myDS.connectionString property via the constructor, whilst having the rest of the properties in a quartz.config in the working directory. However, I get the error:
Provider not specified for DataSource: myDS
So I guess this means that if you use the constructor that accepts the NameValueCollection, then it doesn't bother checking the config file(s).
I know that the quartz.config file is in the right place, because if I put the connectionstring in there and use the default constructor, it all works
In the end, they are all simply named-value pairs.
You can have "most" of them in an .xml file...then "add in" the ones you want via code.
Or have all of them in code.
See the UnitTests for the source code, and you'll see this fairly clearly.
Something like this:
NameValueCollection config = (NameValueCollection)ConfigurationManager.GetSection("quartz");
config.Add("MyCodedUpKey", "MyCodedUpValue");
If you have a "collision" (a "key" in the config file that you want to override..apply some simple name-valued-pair "update existing key" logic"
Check if Key Exists in NameValueCollection

Xcode - exclude files in a custom configuration - better way?

I'm trying to come up with a way to make it easy to switch out our "mock" data services and our live ones. Basically, we'll have live servers with real web services, but for whatever reason, a developer may want to load data from static files (file urls).
I figured I would solve this problem by creating categories that override the methods that fetch the data, thus leaving original code untouched (it has no concept of the "mock" data). I don't want to litter my code with #ifdef.
I can put an #ifdef at the very beginning of each file that has categories in it, and I can set a custom flag in the configuration settings, but I'd rather just have a way to include or exclude the files depending on the configuration. Is that possible? How do you solve this problem?
See http://lists.apple.com/archives/xcode-users/2009/Jun/msg00153.html
The trick is to define EXCLUDED_SOURCE_FILE_NAMES in the configuration you want to exclude the files from, and set the value of that custom build setting to a list of the file names (or a pattern that matches those, and only those, file names).
I would recommend creating two targets one of which has the mock categories included and another one which does not.
When you want to test, just build the target containing the mock categories. Everything else can remain identical.
If you would like to add a file but do not wont to compile it. Go to (for all your targets) project>build phases>compile source and take out the file that you do not want to compile.