Announcement Announcement Module
Collapse
No announcement yet.
How to access MessageSource from a Spring Service? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to access MessageSource from a Spring Service?

    I am using Spring to expose a several services that are being accesed by a rich client via HTTP. I have defined a messageSource bean in my application context, but I am unclear as to how my services should access this. My service implementors, being plane POJOs do not know about the ApplicationContext and therefore cannot call getMessage(..) on the app context. Should I just inject the message source into my service beans so that they can do resource lookup or is there a better best practice? Thanks!

    Edward

  • #2
    You can either make the beans implement the marker interface MessageSourceAware, to have the context injected into them as a MessageSource, or if you do not want to introduce an unneeded spring dependency you can manually inject the "messageSource" bean itself, via a normal property declaration. The latter is normallhy preferred, if a little bit more verbose.

    Comment

    Working...
    X