当前位置:编程学习 > JAVA >>

spring Security3.1 不能创建配置文件里的bean

异常:org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.filterChains': Cannot resolve reference to bean 'org.springframework.security.web.DefaultSecurityFilterChain#1' while setting bean property 'sourceList' with key [1]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.web.DefaultSecurityFilterChain#1': Cannot resolve reference to bean 'myFilter' while setting constructor argument with key [12]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myFilter' defined in class path resource [applicationContext-security.xml]: Cannot resolve reference to bean 'mySecurityMetadataSource' while setting bean property 'securityMetadataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mySecurityMetadataSource' defined in class path resource [applicationContext-security.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [bank.security.MySecurityMetadataSource]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException: You must provide a configuration attribute
配置文件:applicationContext-security.xml
 <http pattern="/js/**" security="none"/>  
        <http use-expressions="true" auto-config="true">  
              
            <form-login />  
            <logout/>  
            <!-- 实现免登陆验证 -->  
            <remember-me />  
            <session-management invalid-session-url="/timeout.jsp">  
                <concurrency-control max-sessions="10" error-if-maximum-exceeded="true" />  
            </session-management>  
            <custom-filter ref="myFilter" before="FILTER_SECURITY_INTERCEPTOR"/>  
        </http>  
        <!-- 配置过滤器 -->  
        <beans:bean id="myFilter" class="bank.security.MySecurityFilter">  
            <!-- 用户拥有的权限 -->  
            <beans:property name="authenticationManager" ref="myAuthenticationManager" />  
            <!-- 用户是否拥有所请求资源的权限 -->  
            <beans:property name="accessDecisionManager" ref="myAccessDecisionManager" />  
            <!-- 资源与权限对应关系 -->  
            <beans:property name="securityMetadataSource" ref="mySecurityMetadataSource" />  
        </beans:bean>  
        <!-- 实现了UserDetailsService的Bean -->  
        <authentication-manager alias="myAuthenticationManager">  
            <authentication-provider user-service-ref="myUserDetailServiceImpl" />  
        </authentication-manager>  
        <beans:bean id="myAccessDecisionManager" class="bank.security.MyAccessDecisionManager"></beans:bean>  
        <beans:bean id="mySecurityMetadataSource" class="bank.security.MySecurityMetadataSource">  
            <beans:constructor-arg name="resourcesDao" ref="resourcesDao"></beans:constructor-arg>  
        </beans:bean>  
        <beans:bean id="myUserDetailServiceImpl" class="bank.security.MyUserDetailServiceImpl">  
            <beans:property name="usersDao" ref="usersDao"></beans:property>  
        </beans:bean>  
MySecurityMetadataSource类:
public class MySecurityMetadataSource implements FilterInvocationSecurityMetadataSource {  
    //由spring调用  
    public MySecurityMetadataSource(ResourcesDao resourcesDao) {  
        this.resourcesDao = resourcesDao;  
        loadResourceDefine();  
    }  
    private ResourcesDao resourcesDao;  
    private static Map<String, Collection<ConfigAttribute>> resourceMap = null;  
  
    public ResourcesDao getResourcesDao() {  
        return resourcesDao;  
    }  
    public void setResourcesDao(ResourcesDao resourcesDao) {  
        this.resourcesDao = resourcesDao;  
    }  
    public Collection<ConfigAttribute> getAllConfigAttributes() {  
        return null;  
    }  
    public boolean supports(Class<?> clazz) {  
        return true;  
    }  
    //加载所有资源与权限的关系  
    private void loadResourceDefine() {  
        if(resourceMap == null) {  
            resourceMap = new HashMap<String, Collection<ConfigAttribute>>();  
            List<Resources> resources = this.resourcesDao.findAll();  
            for (Resources resource : resources) {  
                Collection<ConfigAttribute> configAttributes = new ArrayList<ConfigAttribute>();  
                                //以权限名封装为Spring的security Object  
                ConfigAttribute configAttribute = new SecurityConfig(resource.getName());  
                configAttributes.add(configAttribute);  
                resourceMap.put(resource.getUrl(), configAttributes);  
            }  
        }  
        Set<Entry<String, Collection<ConfigAttribute>>> resourceSet = resourceMap.entrySet();  
        Iterator<Entry<String, Collection<ConfigAttribute>>> iterator = resourceSet.iterator();  
    }  
    //返回所请求资源所需要的权限  
    public Collection<ConfigAttribute> getAttributes(Object object) throws IllegalArgumentException {  
        String requestUrl = ((FilterInvocation) object).getRequestUrl();  
        System.out.println("requestUrl is " + requestUrl);  
        if(resourceMap == null) {  
            loadResourceDefine();  
        }  
        return resourceMap.get(requestUrl);  
    }  
}  
求指教!  抱歉 就还有20分了! --------------------编程问答-------------------- 求来人!求指点! --------------------编程问答-------------------- 没有来帮忙看看的么? --------------------编程问答-------------------- 你resourcesDao的bean 是怎么定义的啊
补充:Java ,  Web 开发
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,