Announcement Announcement Module
Collapse
No announcement yet.
Autowire fields in an AuthenticationSuccessHandler Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Autowire fields in an AuthenticationSuccessHandler

    Hi,

    I'm trying to auto-wire one of my DAOs into my AuthenticationSuccessHandler, because I want to pull user settings from the database when someone logs in.

    My DAO is annotated with @Repository, so it's not defined anywhere in my XML context configuration, meaning to access it I have to auto-wire it or get it through the application context. I've already tried making my handler implement ApplicationContextAware, however the context never finds my DAO bean, even if I explicitly name it. Plus, I'd rather just use @Autowired, because it's cleaner and simpler.

    Of course, to auto-wire the DAO, my AuthenticationSuccessHandler needs to be managed too, so I need to annotate it with @Component and let Spring manage it.

    However, the only property accepted for an authentication success handler is a reference to a bean:
    Code:
    <form-login authentication-success-handler-ref="authenticationSuccessHandler" />
    So, how can I auto-wire something into my authentication success handler, if I can't tell the Spring which class to use rather than which explicit bean?

  • #2
    Why would this be different as normal beans?! The authenticationSuccessHandler is just a bean as anyother bean.

    Add @Autowired to the field in the handler, add the dao to the configuration (either explicit or by component-scanning).

    Comment

    Working...
    X