Announcement Announcement Module
Collapse
No announcement yet.
messageSource inside a jar - how to link to it? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • messageSource inside a jar - how to link to it?

    Hello,

    I am developing an app, making intensive use of a jar file produced by another group at my company. The jar contains a bean messageSource and an own messages.properties file. The jar comes as-is and may not be modified for the purposes of my app.

    My app is supposed to contain an own messages.properties file and (I reckon) another own bean for message resolution.

    At this point I am unable to merge these two beans into one single message service. I have put a reference to a parentMessageSource in the bean in my app. Everything gets loaded fine, I am able to manage messages from the jar, but the messages belonging to my own app cannot be resolved by the messageSource in the jar. I guess this is understandable, the parent does not know about the child.

    From another thread in this forum I see an example where the messageSource bean has a parent with different name, but in my case the bean named "messageSource" is already in the jar and cannot be modified.

    I wish I could just overwrite the messageSource bean in the jar, creating a new one in my own applicationContext.xml, but I guess this it not allowed.

    I hope someone can give me some idea, thanks in advance
    Marco

    - - - - - - - - - - - - -
    How is it possible to add new messages to the messageSource I received with the jar? I see that StaticMessageSource is meant to do that, but it is discouraged for production. I am puzzled. Have a nice day.
    - - - - - - - - - - - - -
    A BIT OF EXPLANATION WHY I AM WILLING TO DO ALL THIS...
    I understand already that I can make my own MessageSource with a parent reference to che messageSource in the jar and wire the child in my classes. My problem arises when I want to use the tag <spring:message> in my JPS's. That tag does not allow to specify a message source and therefore goes straight to the parent messageSource, which does not know anything about the messages of its child. I understand that the ApplicationContext itself takes care of resolving messages, but I cannot see how to tell him to use my child bean instead of the one already named messageSource. The Spring reference tells plainly that the name "messageSource" is mandatory... so that seems to be all about it.
    - - - - - - - - - - - - -
    Last edited by muzietto; Jul 16th, 2008, 05:30 AM. Reason: Wanting to make myself clear...

  • #2
    From another thread in this forum I see an example where the messageSource bean has a parent with different name, but in my case the bean named "messageSource" is already in the jar and cannot be modified.
    ?hmm, it should works. Try this:

    Code:
    <bean id="otherMsgSoruce" class="com.abc.SourceFromOtherJar">
    </bean>
    
    <bean id="messageSource" class="com.xyz.MyMessageSrouce">
      <property name="parentMessageSource" ref="otherMsgSoruce"/>
    </bean>

    Comment


    • #3
      How can this be?

      Sorry, Tannoy but I can't follow you.

      My messageSource in the jar is an org.springframework.context.support.ResourceBundle MessageSource, not a class on its own.

      I am talking about:

      3.8.2. Internationalization using MessageSources

      http://static.springframework.org/sp...-messagesource

      How is it possible to add new messages to the messageSource I received with the jar? I see that StaticMessageSource is meant to do that, but it is discouraged for production. I am puzzled. Have a nice day.

      Comment


      • #4
        since the xml in the jar can't be modified, some solutions on top of my head:

        1) use other bean name well, you have to. In this way, you lost the benift to get message directly from application context. You have to call getMessage() from bean messageSource2

        Code:
        <!--in the jar, can not be modified-->
        <bean id="messageSource" class="com.abc.ResourceBundleMessageSource">
        </bean>
        
        <bean id="messageSource2" class="com.xyz.ResourceBundleMessageSource">
          <property name="parentMessageSource" ref="messageSource"/>
        </bean>
        2) or you can create a wrapper around two message resouces.
        Code:
        public class I18nMessageImpl extends ResourceBundleMessageSource
        		implements I18nMessage {
            public String getMessage(String messageKey) {
            //delegete two message resource
            }
        
            // bean wiring ..
        }
        in this case, you also can not get all messages from application context. So use the I18nMessage in stead.

        Comment


        • #5
          Thank you!

          Thank you for the advices. I like the second the most, I am gonna follow it.
          Have a nice day,
          Marco

          Comment

          Working...
          X