}
@Bean
public MessageResolver messageResolver(){
CustomMessageResolver messageResolver = new CustomMessageResolver();
messageResolver.setEnvironment(env);
String baseDir = env.getProperty("language.baseDir", "/WEB-INF/languages");
if(baseDir.startsWith("/")){
baseDir = servletContext.getRealPath(baseDir);
}
messageResolver.setBaseDir(baseDir);
messageResolver.setJdbcTemplate(jdbcOperations);
messageResolver.setLocaleResolver(localeResolver());
boolean cacheable = env.getProperty("language.cacheable", Boolean.class, Boolean.TRUE);
if(cacheable){
EhCacheFactoryBean cacheFactory = new EhCacheFactoryBean();
//use default cache manager CacheManager.getInstance();
cacheFactory.setCacheName("messageCache");
try {
cacheFactory.afterPropertiesSet();
} catch (Exception e) {
throw new IllegalStateException(e.getMessage(), e);
}
messageResolver.setCacheable(true);
messageResolver.setCache(cacheFactory.getObject());
}else{
messageResolver.setCacheable(false);
}
return messageResolver;
}