@Component注释无效

时间:2014-12-19 19:07:51

标签: spring security components autowired

请告知我在哪里出错。 @Component和@Qualifier不起作用。获取没有这样的bean定义的异常。

我有spring security xml,其中一部分是

<http use-expressions="true" create-session="stateless" >
<form-login login-page="/inventory/auth/login"
        always-use-default-target="true" default-target-url="/inventory/secureauth"         
        authentication-failure-url="/inventory/secureauth/login?login_error=1" 
        username-parameter="username" password-parameter="password" />

    <custom-filter position="PRE_AUTH_FILTER" ref="cookieSessionFilter" />          
</http>

<authentication-manager alias="authenticationManager">
    <authentication-provider ref="userAuthenticationProvider" />
</authentication-manager>

我写了一个AbstractPreAuthenticatedProcessingFilter如下

package com.eim.security;

@Component(value="cookieSessionFilter")
public class CookieSessionFilter extends AbstractPreAuthenticatedProcessingFilter {

 @Autowired
public CookieSessionFilter(@Qualifier(value="authenticationManager") AuthenticationManager authenticationManager) {
    setAuthenticationManager(authenticationManager);
}

请找我的spring dispatcher servlet xml

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:cache="http://www.springframework.org/schema/cache"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:util="http://www.springframework.org/schema/util"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/mvc 
        http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://www.springframework.org/schema/util 
        http://www.springframework.org/schema/util/spring-util.xsd
        http://www.springframework.org/schema/aop 
        http://www.springframework.org/schema/aop/spring-aop.xsd
        http://www.springframework.org/schema/tx 
        http://www.springframework.org/schema/tx/spring-tx.xsd
        http://www.springframework.org/schema/cache
        http://www.springframework.org/schema/cache/spring-cache.xsd">
<context:annotation-config />
<mvc:annotation-driven />

<context:component-scan 
    base-package="com.eim.security, com.eim.glossary.controller">
</context:component-scan>

我收到以下异常

org.springframework.beans.factory.BeanCreationException: Error creating bean with     name 'org.springframework.security.filterChains': Cannot resolve reference to bean 'org.springframework.security.web.DefaultSecurityFilterChain#9' while setting bean property 'sourceList' with key [9]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.web.DefaultSecurityFilterChain#9': Cannot resolve reference to bean 'cookieSessionFilter' while setting constructor argument with key [2]; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'cookieSessionFilter' is defined
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359)

我不知道为什么我得到以下异常,因为我将组件扫描的base-package提供给Spring容器

org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'cookieSessionFilter'

请告知

1 个答案:

答案 0 :(得分:0)

非常感谢M.Deinum

根据您的建议,我通过更新web.xml来移动根上下文中bean的检测。它现在正在运作。

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>WEB-INF/spring-servlet.xml, WEB-INF/eimsgo-security.xml</param-value>
</context-param>

以前,我在servlet级别使用了spring-servlet.xml。现在转移到

谢谢!