1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.settings4j.helper.spring;
18
19 import javax.servlet.ServletContext;
20
21 import org.settings4j.helper.web.DefaultPropertiesLoader;
22 import org.springframework.web.context.ConfigurableWebApplicationContext;
23 import org.springframework.web.context.ContextLoader;
24 import org.springframework.web.context.support.XmlWebApplicationContext;
25
26
27
28
29
30
31
32
33
34
35
36 public class Settings4jContextLoader extends ContextLoader {
37
38
39 private static final org.slf4j.Logger LOG = org.slf4j.LoggerFactory.getLogger(Settings4jContextLoader.class);
40
41
42
43
44
45
46
47 public static final String SETTINGS4J_CONFIG_LOCATION_PARAM = "settings4jContextConfigLocation";
48
49
50 @Override
51 protected void customizeContext(final ServletContext servletContext, final ConfigurableWebApplicationContext wac) {
52 if (wac instanceof XmlWebApplicationContext) {
53
54 createDefaultPropertiesLoader().initDefaultProperties(servletContext);
55
56 final String configLocations = servletContext.getInitParameter(SETTINGS4J_CONFIG_LOCATION_PARAM);
57 LOG.debug("settings4jContextConfigLocation configLocations: {}", configLocations);
58 final String parsedConfigLocations = Settings4jPlaceholderConfigurer.parseStringValue(configLocations);
59 LOG.debug("settings4jContextConfigLocation parsed configLocations: {}", parsedConfigLocations);
60
61 wac.setConfigLocation(parsedConfigLocations);
62 } else {
63 LOG.warn(
64 "Settings4jContextLoader only works with an ApplicationContext from type XmlWebApplicationContext.");
65 }
66 }
67
68
69
70
71
72
73 protected DefaultPropertiesLoader createDefaultPropertiesLoader() {
74 return new DefaultPropertiesLoader();
75 }
76
77 }