Revision 57908
Added by Ioannis Diplas over 4 years ago
CascadingPropertyLoader.java | ||
---|---|---|
1 |
package eu.dnetlib.repo.manager.config; |
|
2 |
|
|
3 |
import org.springframework.beans.BeansException; |
|
4 |
import org.springframework.beans.factory.InitializingBean; |
|
5 |
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; |
|
6 |
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer; |
|
7 |
|
|
8 |
import java.util.Properties; |
|
9 |
|
|
10 |
/** |
|
11 |
* CascadingPropertyLoader loads a number of property files and mergers them together, so that the last properties |
|
12 |
* override the previous. It also supports property expansion like: |
|
13 |
* |
|
14 |
* <code> |
|
15 |
* something = 1 |
|
16 |
* somethingelse = 2 |
|
17 |
* test = ${something}/${somethingelse} |
|
18 |
* </code> |
|
19 |
* |
|
20 |
* <p> |
|
21 |
* And if you override something to XX, then test will become XX/2 |
|
22 |
* </p> |
|
23 |
* |
|
24 |
* |
|
25 |
* @author marko |
|
26 |
* |
|
27 |
*/ |
|
28 |
public class CascadingPropertyLoader extends PropertyPlaceholderConfigurer implements InitializingBean { |
|
29 |
|
|
30 |
private Properties properties; |
|
31 |
|
|
32 |
public void afterPropertiesSet() throws Exception { |
|
33 |
this.properties = mergeProperties(); |
|
34 |
|
|
35 |
// Convert the merged properties, if necessary. |
|
36 |
convertProperties(this.properties); |
|
37 |
|
|
38 |
logger.debug("Properties: " + properties); |
|
39 |
} |
|
40 |
|
|
41 |
@Override |
|
42 |
protected void processProperties(final ConfigurableListableBeanFactory beanFactoryToProcess, final Properties props) throws BeansException { |
|
43 |
super.processProperties(beanFactoryToProcess, props); |
|
44 |
} |
|
45 |
|
|
46 |
public Properties getProperties() { |
|
47 |
return properties; |
|
48 |
} |
|
49 |
|
|
50 |
public void setProperties(final Properties properties) { |
|
51 |
super.setProperties(properties); |
|
52 |
|
|
53 |
this.properties = properties; |
|
54 |
} |
|
55 |
} |
|
56 |
|
Also available in: Unified diff
Replacing XML configuration for Provide with Java equivalent