Results 1 to 3 of 3

Thread: problem with using <spring:message> ..Anyhelp appreciated

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Posts
    4

    Default problem with using <spring:message> ..Anyhelp appreciated

    I am replacing jstl <fmt> with <spring:message> tag in my web application and i m seeing following exception from framework.

    Stack Trace:
    No WebApplicationContext found: no ContextLoaderListener registered? Start server side stack trace: java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoaderListener registered? at org.springframework.web.servlet.support.RequestCon textUtils.getWebApplicationContext(RequestContextU tils.java:84) at org.springframework.web.servlet.support.RequestCon text.initContext(RequestContext.java:203) at org.springframework.web.servlet.support.JspAwareRe questContext.initContext(JspAwareRequestContext.ja va:74) at org.springframework.web.servlet.support.JspAwareRe questContext.(JspAwareRequestContext.java:48) at org.springframework.web.servlet.tags.RequestContex tAwareTag.doStartTag

    I have the following entry in spring config file

    <bean id="messageSource" class="org.springframework.context.support.Resourc eBundleMessageSource">
    <property name="basename"><value>MessageResource</value></property>
    </bean>

    Is this configuration enough to use a resource bundle r m i missing anything.

    I also dissected the source code and realised that "webapplication context "will be binded only when the request goes thru "Dispatcher Servlet".When the page is directly accessed it is noway can go thru the Dispatcher Servlet.Is there any other way of binding this "application context" so that it can able to find "messageSource" bean declared in "spring-servlet.xml".

    Thanks in advance.

  2. #2
    Join Date
    Aug 2004
    Location
    Montréal, Canada
    Posts
    845

    Default

    You can put your messgeSource in a separte applicationContext.xml file and load it using ContextLoaderListener in web.xml.
    Code:
      <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
          WEB-INF/applicationContext.xml
        </param-value>
      </context-param>
    
      <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
      </listener>
    This way you can access the messages from plain jsps without going thru Spring DispatchServlet.
    Hope this helps.
    Omar Irbouh

    Spring Modules Team
    http://irbouh.blogspot.com/

  3. #3
    Join Date
    Oct 2005
    Posts
    4

    Default

    Thanks Omar,it just worked fine.

Posting Permissions

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