August 10, 2005

spring rocks ;) Filters + DI solved!

Writing about web page http://static.springframework.org/spring/docs/1.2.x/api/org/springframework/web/filter/DelegatingFilterProxy.html

So I have a couple of filters which need access to spring beans. Previously I was doing something like:


protected final void initFilterBean() throws ServletException {
super.initFilterBean();
WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());
pageResolver = (PageResolver) wac.getBean("pageResolver");
onInitFilterBean(wac);
}

which was a bit fragile. Anyways, spring allows you to define filters in your applicationContext, complete with DI ;)

in web.xml:


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

Spring will then look for a bean called loadPageFilter in the applicationContext and delegate to that. And of course, you can specify the actual bean name (instead of using the filter-name).

Cool.

P.S. Someone asked me how to do this and I forgot I had blogged about it, I redid this here: link


- One comment Not publicly viewable

  1. Chris May

    Pretty neat. Is there an equivalent for ServletContextListeners ?

    15 Aug 2005, 15:44


Add a comment

You are not allowed to comment on this entry as it has restricted commenting permissions.

August 2005

Mo Tu We Th Fr Sa Su
Jul |  Today  | Sep
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31            

Search this blog

Tags

Galleries

Most recent comments

  • Interesting… While I'm not completely convinced in such microbenchmarks, I'm pretty sure that 1ms … by Alexander Snaps on this entry
  • Hello. I bought the book yesterday. I was trying to find the source code for chapter 11 and chapter … by Suleman on this entry
  • http://woosight.net/account/login?username=demo by live mashup demo on this entry
  • Thanks mate ….. This blog was really helpful. by Maaz Hurzuk on this entry
  • Ty. Not directly helpful for my problem, but pointed me in the right direction. You will also get th… by Mike E. on this entry

Blog archive

Loading…
Not signed in
Sign in

Powered by BlogBuilder
© MMXXI