@Autowired注释在从applicationcontext自定义过滤器类访问时返回错误。
内部应用程序上下文
<sec:custom-filter ref="userFilter"position="BASIC_AUTH_FILTER" /> <beans:bean id="userFilter" class="com.xxx.xxx.web.xxx.UserFilter">
UserFilter类从数据库访问服务。
@Autowired @Qualifier("userService")
private UserService userService;
在我使用的服务类中,如下所示。
Service(value="userService")
Component("userService")
public class UserService.
固有的autowire注释方法我按照下面的方法正常工作。
UserService userService= new UserService();
我在applicationcontext过滤器类中使用autowire批注时遇到错误。 我可以在应用程序中提供的所有其他类中使用Autowire注释。
java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: Root WebApplicationContext: startup date [Fri Mar 06 17:41:56 IST 2015]; root of context hierarchy
at org.springframework.context.support.AbstractApplicationContext.getApplicationEventMulticaster(AbstractApplicationContext.java:346) [spring-context-4.0.6.RELEASE.jar:4.0.6.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:333) [spring-context-4.0.6.RELEASE.jar:4.0.6.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:880) [spring-context-4.0.6.RELEASE.jar:4.0.6.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:841) [spring-context-4.0.6.RELEASE.jar:4.0.6.RELEASE]
at org.springframework.web.context.ContextLoader.closeWebApplicationContext(ContextLoader.java:579) [spring-web-4.0.6.RELEASE.jar:4.0.6.RELEASE]
at org.springframework.web.context.ContextLoaderListener.contextDestroyed(ContextLoaderListener.java:115) [spring-web-4.0.6.RELEASE.jar:4.0.6.RELEASE]
at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:4980) [catalina.jar:7.0.47]
at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5626) [catalina.jar:7.0.47]
at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:232) [catalina.jar:7.0.47]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:160) [catalina.jar:7.0.47]
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559) [catalina.jar:7.0.47]
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549) [catalina.jar:7.0.47]
at java.util.concurrent.FutureTask.run(FutureTask.java:262) [na:1.7.0_67]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [na:1.7.0_67]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [na:1.7.0_67]
at java.lang.Thread.run(Thread.java:745) [na:1.7.0_67]
2015-03-06 17:41:57,425 WARN [localhost-startStop-1] - [org.springframework.web.context.support.XmlWebApplicationContext]- Exception thrown from LifecycleProcessor on context close
java.lang.IllegalStateException: LifecycleProcessor not initialized - call 'refresh' before invoking lifecycle methods via the context: Root WebApplicationContext: startup date [Fri Mar 06 17:41:56 IST 2015]; root of context hierarchy
at org.springframework.context.support.AbstractApplicationContext.getLifecycleProcessor(AbstractApplicationContext.java:359) [spring-context-4.0.6.RELEASE.jar:4.0.6.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:888) [spring-context-4.0.6.RELEASE.jar:4.0.6.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:841) [spring-context-4.0.6.RELEASE.jar:4.0.6.RELEASE]
at org.springframework.web.context.ContextLoader.closeWebApplicationContext(ContextLoader.java:579) [spring-web-4.0.6.RELEASE.jar:4.0.6.RELEASE]
at org.springframework.web.context.ContextLoaderListener.contextDestroyed(ContextLoaderListener.java:115) [spring-web-4.0.6.RELEASE.jar:4.0.6.RELEASE]
at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:4980) [catalina.jar:7.0.47]
at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5626) [catalina.jar:7.0.47]
at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:232) [catalina.jar:7.0.47]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:160) [catalina.jar:7.0.47]
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559) [catalina.jar:7.0.47]
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549) [catalina.jar:7.0.47]
at java.util.concurrent.FutureTask.run(FutureTask.java:262) [na:1.7.0_67]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [na:1.7.0_67]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [na:1.7.0_67]
at java.lang.Thread.run(Thread.java:745) [na:1.7.0_67]
Mar 06, 2015 5:41:57 PM org.apache.catalina.core.StandardContext listenerStop
SEVERE: Exception sending context destroyed event to listener instance of class org.springframework.web.context.ContextLoaderListener
java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext
at org.springframework.context.support.AbstractRefreshableApplicationContext.getBeanFactory(AbstractRefreshableApplicationContext.java:170)
at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:921)
at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:895)
at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:841)
at org.springframework.web.context.ContextLoader.closeWebApplicationContext(ContextLoader.java:579)
at org.springframework.web.context.ContextLoaderListener.contextDestroyed(ContextLoaderListener.java:115)
at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:4980)
at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5626)
at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:232)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:160)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
请查看以下申请背景
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.2.xsd&#34;&GT;
<!-- Import service layer -->
<beans:import resource="classpath:serviceDEVContext.xml" />
<!-- <beans:bean id="authService"
class="com.bosch.bdxdb.web.userservice.AuthServiceImpl" /> -->
<!-- windows authentication provider -->
<beans:bean id="waffleWindowsAuthProvider"
class="waffle.windows.auth.impl.WindowsAuthProviderImpl" />
<!-- collection of security filters -->
<beans:bean id="negotiateSecurityFilterProvider"
class="waffle.servlet.spi.NegotiateSecurityFilterProvider">
<beans:constructor-arg ref="waffleWindowsAuthProvider" />
<beans:property name="protocols">
<beans:list>
<beans:value>Negotiate</beans:value>
<beans:value>NTLM</beans:value>
</beans:list>
</beans:property>
</beans:bean>
<beans:bean id="basicSecurityFilterProvider"
class="waffle.servlet.spi.BasicSecurityFilterProvider">
<beans:constructor-arg ref="waffleWindowsAuthProvider" />
</beans:bean>
<beans:bean id="waffleSecurityFilterProviderCollection"
class="waffle.servlet.spi.SecurityFilterProviderCollection">
<beans:constructor-arg>
<beans:list>
<beans:ref bean="negotiateSecurityFilterProvider" />
<beans:ref bean="basicSecurityFilterProvider" />
</beans:list>
</beans:constructor-arg>
</beans:bean>
<sec:global-method-security
secured-annotations="enabled" />
<sec:http security="none" pattern="/favicon.ico" />
<!-- spring filter entry point -->
<sec:http entry-point-ref="negotiateSecurityFilterEntryPoint">
<sec:intercept-url pattern="/**" access="IS_AUTHENTICATED_FULLY" />
<sec:custom-filter ref="userFilter"
position="BASIC_AUTH_FILTER" />
</sec:http>
<beans:bean id="negotiateSecurityFilterEntryPoint"
class="waffle.spring.NegotiateSecurityFilterEntryPoint">
<beans:property name="Provider"
ref="waffleSecurityFilterProviderCollection" />
</beans:bean>
<beans:bean id="waffleSpringAuthenticationProvider" class="waffle.spring.WindowsAuthenticationProvider">
<beans:property name="AuthProvider" ref="waffleWindowsAuthProvider" />
</beans:bean>
<!-- spring authentication provider -->
<sec:authentication-manager alias="authenticationProvider"/>
<!-- <sec:authentication-manager alias="authenticationProvider">
<sec:authentication-provider ref="waffleSpringAuthenticationProvider" />
</sec:authentication-manager> -->
<!-- <sec:authentication-manager alias="authenticationManager"> <sec:authentication-provider
user-service-ref="authService"></sec:authentication-provider> </sec:authentication-manager> -->
<!-- spring security filter -->
<beans:bean id="waffleNegotiateSecurityFilter" class="com.xxx.xxx.web.waffle.userFilter">
<beans:property name="Provider"
ref="waffleSecurityFilterProviderCollection" />
<beans:property name="AllowGuestLogin" value="false" />
<beans:property name="PrincipalFormat" value="fqn" />
&LT; /豆类:性&gt; - &GT;