Issue
I'm loading application settings such as JDBC connection info from a properties file using PropertyPlaceholderConfigurer
. I'd like to also have other settings such as default locale and timezone as properties.
But I'm unsure of the best method to execute Locale.setDefault()
and TimeZone.setDefault()
. I want them run early in startup and only once. Is there a proper way in Spring to execute some code FIRST, before other code is executed? Any suggestions?
I know I can specify default values on the command line, but this application will get installed in many places and I want to avoid problems caused by someone forgetting to specify -Duser.timezone=UTC
or whatever.
Solution
I've used a ServletContextListener
. In contextInitialized(..)
TimeZone.setDefault(..)
is called.
It won't be taken into account if you rely on the timezone in any constructor or @PostConstruct
/ afterPropertiesSet()
though.
If you need it, take a look at this question
Answered By - Bozho
Answer Checked By - David Marino (JavaFixing Volunteer)