Results 1 to 2 of 2

Thread: How to access MessageSource from a Spring Service?

  1. #1
    Join Date
    Dec 2004
    Posts
    2

    Default 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. #2
    Join Date
    Aug 2004
    Location
    Toronto, Canada
    Posts
    736

    Default

    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.
    Colin Sampaleanu
    SpringSource - http://www.springsource.com

Similar Threads

  1. Access singleton map from spring service?
    By rhodepc in forum Container
    Replies: 2
    Last Post: Oct 13th, 2005, 06:23 AM
  2. Replies: 10
    Last Post: Jul 8th, 2005, 02:24 AM
  3. Stack Overflow
    By rayho222 in forum Container
    Replies: 6
    Last Post: May 17th, 2005, 03:42 AM
  4. Replies: 14
    Last Post: Feb 21st, 2005, 05:41 PM
  5. Replies: 6
    Last Post: Oct 8th, 2004, 02:21 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •