views:

78

answers:

2

Hi all,

I followed this article : Spring and servlet filters to add a filter on a specific URL.

I added my 'foo' class, which implements 'Filter' interface.

But when I access to my specific URL, an Java exception is catch :

java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoaderListener registered?

My technical environment is :

  • Spring 2.5
  • BlazeDS
  • Apache TomCat

Thank you very much for your help,

Regards,

Anthony

+1  A: 

DelegatingFilterProxy works by delegating the work of the filter to a bean in the root webapp spring context. If you're getting that error, then you haven't defined one.

You need to make sure something like the following is in your web.xml:

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>  

This will obtain the context's bean definitions from /WEB-INF/application.xml

skaffman
A: 

Hi Skaffman

Thanks for your answer.

This is my web.xml file content :

<display-name>XXX Server Webapp</display-name>

    <listener>
            <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <filter>
            <filter-name>foo</filter-name>
            <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    </filter>

    <filter-mapping>
            <filter-name>foo</filter-name>
            <url-pattern>/fbauth</url-pattern>
    </filter-mapping> 

<!-- Spring MVC Servlet (that will route HTTP requests to BlazeDS) -->
<servlet>
    <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring-main-config.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

<!-- We are only using BlazeDS AMF channels to communicate with FlexClient, so let's map URLs accordingly. -->
<servlet-mapping>
    <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
    <url-pattern>/messagebroker/*</url-pattern>
</servlet-mapping>

<!-- Other configs -->
<welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>MyFlex.swf</welcome-file>
</welcome-file-list>

<!-- The application developer can also select to set the HTTP Session time-out parameter 
    when the application is packaged. This value is stored in the web.xml file for the Web application.
    This setting overrides any session time-outs defined from the Administrative Console. Alter this setting 
    by repackaging the application with a new value, or by modifying the web.xml file. 
    "session-timeout" is an integer value for the desired session time-out in minutes. 
-->
<session-config>
    <session-timeout>30</session-timeout>
</session-config>

and in my spring-main-config.xml file content, I had my bean (which implements javax.servlet.Filter interface:

<bean name="foo" class="com.Foo">

But, now my TomCat server can't start with this configuration.

Help me please

Thank you very much,

Anthony

Anthony