我的 Autowiring 在 Controller 和 Controller 下面的所有子类中工作正常。但是当我尝试从 Spring Security 模块 Autowiring 任何 bean(使用注释)时,例如通过 UserDetails 或通过我的自定义注销处理程序。
我已阅读并找到了两种解决方法 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>
请帮忙..
最佳答案
这表明您的 Autowiring 注释尚未激活。 包括
<context:annotation-config>
在您的database-context.xml、application-security.xml 文件中。
关于java - Autowired 在自定义注销处理程序和自定义用户详细信息中给出 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22884096/