views:

100

answers:

1

Hi! Spring seems to resolve and create the autowired objects just fine on boot up. But when I try to access them they come back as null. Anyone have any guesses on what might be going on?

Also XML info is blank as I'm only allowed one hyperlink...

<beans  xmlns="" 
 xmlns:xsi=""
 xmlns:p="" 
 xmlns:mvc=""    
 xmlns:context=""
 xsi:schemaLocation="...only allowed one hyperlink" default-autowire="byName">

 <mvc:annotation-driven />

<context:component-scan base-package="com.blah.controller"/>
<context:component-scan base-package="com.blah.*.service"/>
<context:component-scan base-package="com.blah.*.dao"/>

<context:annotation-config />

public class AuthFilter extends UsernamePasswordAuthenticationFilter {

@Autowired
private ProfileService profileService;
    //.... Do more stuff below that shows profileService coming back as null.

}

I was able to use a debugger to show that the object was being initialized. I can paste my logs here if you guys want but that's a lot to back edit :).

Adding a bit to this where authfilter is defined:

 <b:bean id="authenticationFilter" class="com.blah.auth.AuthFilter">
    <b:property name="authenticationManager" ref="authenticationManager" />
    <b:property name="filterProcessesUrl" value="/login/validate" />
    <b:property name="usernameParameter" value="username" />
    <b:property name="passwordParameter" value="password" />
    <b:property name="authenticationSuccessHandler" ref="authSuccessHandler" />
    <b:property name="authenticationFailureHandler" ref="authFailureHandler" />
</b:bean>

The component scan is in springapp-servlet.xml

I've created a pastebin of the boot logs. No dice with moving the component scan. http://pastebin.com/ttC5MPnQ

+1  A: 
  • see if the there is something suspicious in the logs
  • it appears to me that AuthFilter is not a spring bean - either map it in the xml config, or annotate it with @Component.
  • remove default-autowire="byName" if you don't have a compelling reason to have it set so.
  • make sure you use that filter from within the context, and not instantiating it yourself.
  • make sure you are not referring to a bean defined in a parent context (for example - a bean defined in applicationContext.xml can't access a bean defined in dispatcher-servlet.xml)
  • place a component-scan in the applicationContext.xml (not the servlet one). (You can retain the one in the servlet xml but limit it to web packages only)
Bozho
Hey Bohzo I updated the text with edit going into more detail.
Cay
@user443055 see updated (the last bullet)
Bozho
@Bozho Take a look at the pastebin I've added if you could. I've attached the logs. Thanks for the help!
Cay
I don't see a problem there.. there is "access denied" for the user, but that's a usecase.
Bozho
Well atleast I'm not the only one lost :)
Cay