我的autowire可以在Controller和控制器下面的所有子类中正常工作。但是当我尝试从Spring Security模块中通过UserDetails或通过我的customlogout处理程序自动装配任何bean(使用注释)时。
我已阅读并找到两种解决方法 1.删除 2.将一些代码移动到父context.xml。但看起来这对我没有帮助。
我的web.xml ...
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<!-- The definition of the Root Spring Container shared by all Servlets
and Filters -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring/database-context.xml,
/WEB-INF/spring/application-security.xml
</param-value>
</context-param>
我的servlet-context文件包含以下内容:....
<mvc:resources mapping="/resources/**" location="/" />
<!-- Resolves views selected for rendering by @Controllers to .jsp resources
in the /WEB-INF/views directory -->
<beans:bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>
<context:component-scan base-package="com.inventory" />
<beans:bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<beans:property name="basename" value="classpath:messages"></beans:property>
<beans:property name="defaultEncoding" value="UTF-8"></beans:property>
</beans:bean>
请帮助..
答案 0 :(得分:2)
表示您的自动装配注释未激活。 包括
<context:annotation-config>
在您的database-context.xml,application-security.xml文件中。