I am trying to load the properties files located in the tomcat conf folder but the code below ends up causing a Missing Resource exception.If I use a property placeholder I can load properties files from tomcat conf fine.
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename">
<value>file:${catalina.base}/conf/messages</value>
</property>
</bean>
If you're trying to externalize your resources and use ResourceBundle this is how I did it using ClassLoader.
private static ClassLoader loader;
private static void setUp()
{
String path = System.getProperty("catalina.base");
File file = new File(path +"/conf/error_messages");
URL[] urls = new URL[0];
try {
urls = new URL[]{file.toURI().toURL()};
} catch (MalformedURLException e) {
e.printStackTrace();
}
loader = new URLClassLoader(urls);
}
Now when I need to load the correct messages: ex: errors_en.properties located outside the application.
ResourceBundle.getBundle("errors", requestLocale, loader);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.