I\'m loading application settings such as JDBC connection info from a properties file using PropertyPlaceholderConfigurer. I\'d like to also have other settings
I found Spring loads some of its default beans including other beans before calling the contextInitialized method, so, here is a better approach "draft" that I can think of, let me know if you see any concern:
public class SystemPropertyDefaultsInitializer
implements WebApplicationInitializer{
private static final Logger logger = Logger
.getLogger(SystemPropertyDefaultsInitializer.class);
@Override
public void onStartup(ServletContext servletContext)
throws ServletException {
logger.info("SystemPropertyWebApplicationInitializer onStartup called");
// can be set runtime before Spring instantiates any beans
// TimeZone.setDefault(TimeZone.getTimeZone("GMT+00:00"));
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
// cannot override encoding in Spring at runtime as some strings have already been read
// however, we can assert and ensure right values are loaded here
// verify system property is set
Assert.isTrue("UTF-8".equals(System.getProperty("file.encoding")));
// and actually verify it is being used
Charset charset = Charset.defaultCharset();
Assert.isTrue(charset.equals(Charset.forName("UTF-8")));
// locale
// set and verify language
}
}