You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It is possible to define properties to only take effect in a certain environment.
108
+
### Profiles
109
+
Profiles allow you to map properties to different profiles - for example, dev, test, prod or mock.
110
+
We can activate these profiles in different environments to set(override) the properties we need.
111
+
The profile property is generally to be defined as either an OS environment variable or a JVM system property.
112
+
However, it can be set in a properties file which is useful in unit testing or testing on a local environment.
89
113
90
-
When the runtime property `bordertech.config.environment` is set, it is used as the suffix for each property lookup:
114
+
When a property with the key `bordertech.config.profile` is set, it is used as the suffix for each property lookup:
91
115
92
116
```java properties
93
-
## MOCKEnvironment
94
-
bordertech.config.environment=MOCK
117
+
## MOCKEnvironment set as an Environment or JVMSystem property only
118
+
bordertech.config.profile=MOCK
95
119
96
120
my.example.property.MOCK=mocking
97
121
my.example.property.PROD=proding
98
122
my.example.property=defaulting
99
123
```
100
124
101
-
If no property exists with the current environment suffix then the default property (ie no suffix) value is used.
125
+
The Environment Suffix `bordertech.config.environment` feature has been deprecated and will be removed in the next
126
+
major release but is still honoured within the profile feature.
127
+
128
+
The order of precedence:
129
+
-`bordertech.config.profile` defined as a property anywhere
130
+
-`bordertech.config.environment` defined as a property anywhere(Deprecated - to be removed next major release)
102
131
103
132
### Touchfile
104
133
@@ -174,7 +203,8 @@ The following methods in the `Config` class are useful for unit testing:
174
203
175
204
## Configuration
176
205
177
-
The initial configuration of `Config` can be overridden by setting properties in a file `bordertech-config.properties`. The file name can be overriden via a System or Environment property `BT_CONFIG_FILE`.
206
+
The initial configuration of `Config` can be overridden by setting properties in a file `bordertech-config.properties`.
207
+
The default `bordertech-config.properties` file name can also be overriden via a System or Environment property `BT_CONFIG_FILE`.
[ConfigurationLoader](https://github.com/BorderTech/java-config/blob/master/src/main/java/com/github/bordertech/config/ConfigurationLoader.java) is the [SPI](https://docs.oracle.com/javase/tutorial/sound/SPI-intro.html) interface for classes that can load a custom configuration.
208
238
209
-
By default, the SPI lookup is enabled and if found, will be appended to the default implementation.
239
+
By default, the SPI lookup is enabled and if found, it will create the custom configuration
240
+
241
+
If the `bordertech.config.spi.append.default` is true the Default Configuration will also be appended to the configuration.
242
+
243
+
### Best Practice
244
+
245
+
When using java-config in a container and setting specific properties for that container instance,
246
+
this can be achieved by property file(s) placed in the container that can be referred to and included within the application at runtime.
0 commit comments