Announcement Announcement Module
Collapse
No announcement yet.
problem with using <spring:message> ..Anyhelp appreciated Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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.

    Comment


    • #3
      Thanks Omar,it just worked fine.

      Comment

      Working...
      X