I am using ReloadableResourceBundleMessageSource
in my web project, and I inject the class to a servlet, the problem is that I want to inject the class using Spring annotations but it doesn't seem to work? My code is:
my.xml
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basenames">
<list>
<value>classpath:myList</value>
</list>
</property>
<property name="cacheSeconds" value="1"/>
</bean>
myServletClass.java
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("my.xml");
String message = applicationContext.getMessage(message, null, "Default
", null);
}
How do I inject the ReloadableResourceBundleMessageSource
using annotations?
Change the bean to autowire by name
Autowire the Message Source within your Servlet
Directory Structure
src/main/resources/myList.properties
If you are not using Spring MVC you may need to create a Spring application context when starting your application. This can be configured in your Web.xml file using the ContextLoaderListener.
Web.xml
Did you try this in your servlet?
Then, when you want to gain access to the bean:
below is my current company project xml:
and I am using two properties file:
messages_es.properties
andmessages_en.properties
for language.I hope this will help you.