Spring似乎解决了并且在启动时创建了自动装配的对象。但是当我尝试访问它们时,它们会返回null。任何人都对可能发生的事情有任何猜测?
此外,XML信息为空,因为我只允许一个超链接......
<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.
}
我能够使用调试器来显示该对象正在初始化。如果你们想要的话,我可以在这里粘贴我的日志,但是这需要很多东西来编辑:)。
在定义authfilter的地方添加一点:
<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>
组件扫描位于springapp-servlet.xml
中我已经创建了启动日志的pastebin。移动组件扫描没有骰子。 http://pastebin.com/ttC5MPnQ
答案 0 :(得分:3)
AuthFilter
不是一个弹簧bean - 要么将其映射到xml配置中,要么用@Component
注释它。 default-autowire="byName"
,请将其删除。applicationContext.xml
中定义的bean无法访问dispatcher-servlet.xml
中定义的bean)component-scan
(而不是servlet)中放置applicationContext.xml
。 (您可以将其保留在servlet xml中,但仅限于Web包)