Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ways to access a MessageSource without using MessageSourceAware in the Spring MVC framework

I have couple of servlets designed to hold its own message source, but there is a single static function which uses this message source as backup and in normal case uses a global BDB to retrieve localized text.

I wanted to know if there is a way to retrieve the MessageSource for the context of the servlet which is calling this global static function ?

I can not use MessageSourceAware in all the servlets. I have looked into the Spring documentation and found MessageSourceAware and @autowired properties. I can not use the annotation because i am using spring 2.0.

Any help appreciated.

Thanks, Parth

like image 228
Parth Avatar asked May 17 '11 07:05

Parth


1 Answers

If your MessageSource is defined within your WebApplicationContext, you can retrieve it via:

WebApplicationContext webAppContext = RequestContextUtils.getWebApplicationContext(request);
MessageSource messageSource = webAppContext.getBean("messageSource");
like image 114
RicoZ Avatar answered Nov 11 '22 10:11

RicoZ