0

I have a filter which checks third part session variables and cookies to determine if a given user is logged in. In this servlet, I have to retrieve user's data (if user is logged in 3rd party session, this filter queries a database to check authorizations, for example).

But @Autowired services (eg. userService) are being null in runtime, throwing null point exceptions. Is there a trick in order to autowire components in filters, differently of what we do in servlets? Thanks!

Alex
  • 3,325
  • 11
  • 52
  • 80
  • 1
    Your filter isn't spring managed but managed by your servlet container. Make the Filter a spring managed bean and replace the one in the web.xml with a `DelegatingFilterProxy`. – M. Deinum Oct 02 '14 at 14:52
  • @M.Deinum, I'm not very used on Spring. Have you a link where I can find how I could implement this bean? – Alex Oct 02 '14 at 15:05
  • 1
    I deleted my answer, because M. Deinum is right. – luboskrnac Oct 02 '14 at 15:44
  • Your question is effectively a duplicate, but the answers in the other post had no example of `DelegatingFilterProxy` usage, so I've just posted one [there](http://stackoverflow.com/a/26165117/3545273) – Serge Ballesta Oct 02 '14 at 16:22
  • Answer: Problem was occouring because application-config.xml was not properly configured. There's a need of tag in order to turn Spring aware of beans configuration in root context. – Alex Oct 03 '14 at 18:42

0 Answers0