@Resource(name="messageSource")
private ResourceBundleMessageSource messageSource;
xml:
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename" value="message-info"></property><!--此文件一定要放到src下 由于我的项目是用maven搭建需要放到src/main/resources下-->
</bean>
vaadin 调用:
protected com.xq.controller.HelloWorld getNewApplication(HttpServletRequest request)
throws ServletException {
// TODO Auto-generated method stub
WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(request.getSession().getServletContext());
return (com.xq.controller.HelloWorld) wac.getBean(com.xq.controller.HelloWorld.class);
}
public void init(ServletConfig config) throws ServletException{
super.init(config);
WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(
config.getServletContext());
ResourceBundleMessageSource messageSource=(ResourceBundleMessageSource)wac.getBean(ResourceBundleMessageSource.class);
System.out.println(messageSource.getMessage("nihao", null ,Locale.CHINA));
com.xq.controller.HelloWorld application = (com.xq.controller.HelloWorld) wac.getBean(com.xq.controller.HelloWorld.class);
clazz = application.getClass();
}