Announcement Announcement Module
Collapse
No announcement yet.
messageSource in defined in application context loaded by dispatchservlet Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • messageSource in defined in application context loaded by dispatchservlet

    Hello,

    I am using SpinrMVC+Hibernate+Tomcat.

    I have pretty standard applicationcontext defined in my web app.

    My DispatchServlet is named "action" and it loads action-servlet.xml automatically;
    I defined contextLoaderlistener which loads applicationContext-resource.xml, applicationContext-service.xml and applicationContext-dao.xml.

    At first I define "messageSource" bean in action-servlet.xml . Then I wrote a jsp (this is a standalone jsp, and it does not need DispatchServlet) and this jsp accesses i18n message using <spring:message code="msg1">. Unfortunately, I got error saying that "No message found under code 'msg1' for locale en_US".

    Then I move the declaration of messageSource in applicationContext-resource.xml and everything works.

    So my question is, does Spring treat applicationContext loaded by DispatchServlet and contextLoaderListener differently? I thought one web app only has one ApplicationContext, even you have multiple appicationcontext xml files.

    Please help.

    Thanks,
    Joe
    Last edited by joeserel; Nov 8th, 2005, 02:03 AM.

  • #2
    Originally posted by joeserel
    So my question is, does Spring treat applicationContext loaded by DispatchServlet and contextLoaderListener differently? I thought one web app only has one ApplicationContext, even you have multiple appicationcontext xml files.
    The application-context is a parent of the servlet-context. Thus beans defined in the application-context are visible from within the servlet-context but not vice versa.

    I guess the lookup of the message source uses the application-context, therefore not taking into account your servlet-context.

    Regards,
    Andreas

    Comment


    • #3
      Andreas,

      You were talking about "servlet context"? Or do you mean "application context loaded by servlet"? Not sure I understand you correctly...


      I am not using any servlet context. The application context loaded by DispatchServlet is still Spring application context. Compared with the application contexts loaded by ContentLoaderListener, the only difference is that it is automatically loaded by DispatchServlet based on the servlet name.


      Joe
      Last edited by joeserel; Nov 9th, 2005, 12:12 AM.

      Comment


      • #4
        You are right. My use of words has been inaccurate. Indeed I meant the application context loaded by the servlet.

        Sorry for confusion,
        Andreas

        Comment

        Working...
        X