We are loading properties from an external file using @PropertySources
. Now I want to enable/disable @Aspect
based on a property. I tried using @
It seems Spring by default loads some properties at initialization and unless until you specifically write logic to overwrite them (like the one I wrote in MainClass.java
) there is no option to override those. Some of these include (logging.file, key used in @ConditionalonExpression).
application.properties
in your classpath. The variables loaded at the earlier stages are always read from this file. challenge: I've tight coupled all my properties into the jar and in order to change the values I've to recompile and relaunch the Jar.application.properties
as application-profile.properties
. challenge: I've to create so many profiles and still the previous challenge exists.-Dproperty.key=value
. challenge:seriously? How many properties am I supposed to send as JVM parameter?ApplicationContextInitialize
and override initialize
method.challenge:Overriding Spring's default behaviour is not recommended as well as isn't it an overkill to use this just for reading property file?Use -Dspring.config.location
to specify the property files. In this case, always spring reads the properties only from the specified location(s). You can provide multiple property files as well. Refer this for much more details. It seems if you give property locations as Directories spring loads them in reverse order. But if you specify files it follows the order specified.
Note: All these can be combined together. To know about precedence refer this.