:创建名称为' expressionHandler'的bean时出错

时间:2016-06-29 06:46:29

标签: spring acl

我在使用spring acl时遇到错误,我只是将一些类范围更改为自定义范围,并且在部署应用程序时我现在收到错误 :创建名称为' expressionHandler'的bean时出错

完整筹码:

bean初始化失败;嵌套异常是org.springframework.beans.factory.BeanCreationException:创建名称为' expressionHandler'的bean时出错在类路径资源[spring-security-acl.xml]中定义:无法解析对bean' permissionEvaluator'的引用设置bean属性' permissionEvaluator&#39 ;;嵌套异常是org.springframework.beans.factory.BeanCreationException:创建名称为' permissionEvaluator'的bean时出错在类路径资源[spring-security-acl.xml]中定义:无法解析对bean的引用' aclService'设置构造函数参数时;嵌套异常是org.springframework.beans.factory.UnsatisfiedDependencyException:创建名称为' aclService'的bean时出错在类路径资源[spring-security-acl.xml]中定义:通过构造函数参数表达的不满意的依赖关系,类型为[org.springframework.security.acls.jdbc.LookupStrategy]的索引1:无法转换类型[org]的构造函数参数值.jboss.jca.adapters.jdbc.WrapperDataSource]到必需的类型[org.springframework.security.acls.jdbc.LookupStrategy]:无法转换类型' org.jboss.jca.adapters.jdbc.WrapperDataSource&#的值39;要求的类型' org.springframework.security.acls.jdbc.LookupStrategy&#39 ;;嵌套异常是java.lang.IllegalStateException:无法将类型[org.jboss.jca.adapters.jdbc.WrapperDataSource]的值转换为所需类型[org.springframework.security.acls.jdbc.LookupStrategy]:没有匹配的编辑器或转换策略结果

配置文件 1- appConfig.xml

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-4.1.xsd">


    <bean id="jsonMessageConverter"
        class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter" />

    <bean id="multipartResolver"
        class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <property name="maxUploadSize" value="50000000"/>
    </bean>


    <bean name="myService" class="com.mypackage.test.business.serviceImpl.myService" scope="CustomeScope" lazy-init="true"/>


 </beans>

2 - 弹簧 - 安全的访问控制列表

 <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:security="http://www.springframework.org/schema/security"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:jdbc="http://www.springframework.org/schema/jdbc" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
            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">

    <security:global-method-security pre-post-annotations="enabled">
        <!-- Reference to a custom expression handler with ACL support -->
        <security:expression-handler ref="expressionHandler" />
    </security:global-method-security>  

    <!-- A customized expression handler
        permissionEvaluator: a reference to a custom PermissionEvaluator
        roleHierarchy: defines the role order -->
    <bean id="expressionHandler" class="org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler"  scope="CustomeScope"
        p:permissionEvaluator-ref="permissionEvaluator"
         /> 

    <!-- A customized PermissionEvaluator that evaluates permissions via the ACL module -->
    <bean class="com.aricent.ips.config.AclPermissionEvaluatorCustom" id="permissionEvaluator" scope="CustomeScope">
        <!-- Reference to the ACL service which performs JDBC calls to an ACL database -->
        <constructor-arg ref="aclService"/>
    </bean>

    <!-- A customized ACL service which provides default JDBC implementation -->
    <bean class="org.springframework.security.acls.jdbc.JdbcMutableAclService" id="aclService" scope="CustomeScope">
        <constructor-arg  index="0" ref="dataSourceDynamic"/>
        <constructor-arg  index="1" ref="lookupStrategy" />
        <constructor-arg  index="2" ref="aclCache"/>
    </bean>

    <!-- A lookup strategy for optimizing database queries -->
    <bean id="lookupStrategy" class="com.myPackage.test.config.BasicLookupStrategyCustom" scope="CustomeScope">
        <constructor-arg ref="dataSourceDynamic"/>
        <constructor-arg ref="aclCache"/>
        <constructor-arg ref="aclAuthorizationStrategy"/>
        <constructor-arg ref="auditLogger"/>
    </bean>

    <!-- A MySQL datasource with pooling capabalities for the ACL module -->


    <!-- An ACL cache to minimize calls to the ACL database -->   
    <bean id="aclCache" class="org.springframework.security.acls.domain.EhCacheBasedAclCache">
        <constructor-arg>
            <bean class="org.springframework.cache.ehcache.EhCacheFactoryBean">
                <property name="cacheManager" >
                    <bean class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean" p:shared="true" />
                </property>
                <property name="cacheName" value="aclCache"/>
            </bean>
        </constructor-arg>
    </bean>

    <!-- An ACL authorization strategy to determine whether a principal is permitted to call administrative methods -->
    <bean id="aclAuthorizationStrategy" class="org.springframework.security.acls.domain.AclAuthorizationStrategyImpl">
        <constructor-arg>
            <list>
                <bean class="org.springframework.security.core.authority.SimpleGrantedAuthority">
                    <constructor-arg value="ADMIN"/>
                </bean>
                <bean class="org.springframework.security.core.authority.SimpleGrantedAuthority">
                    <constructor-arg value="ADMIN"/>
                </bean>
                <bean class="org.springframework.security.core.authority.SimpleGrantedAuthority">
                    <constructor-arg value="ADMIN"/>
                </bean>
            </list>
        </constructor-arg>
    </bean>

    <!-- An audit logger used to log audit events -->
    <bean id="auditLogger" class="org.springframework.security.acls.domain.ConsoleAuditLogger"/>

    <!-- Defines the role order -->
    <!-- http://static.springsource.org/spring-security/site/docs/3.0.x/apidocs/org/springframework/security/access/hierarchicalroles/RoleHierarchyImpl.html -->

</beans>

任何帮助表示赞赏。 感谢。

1 个答案:

答案 0 :(得分:0)

问题出在租户对象的创建中,我把它放在一个基于名称关键字的地图中,并且由于我一直得到同一个名字,我通过区分地图键来解决它

public class TenantScope implements Scope {

Map <String,Object> map=new HashMap<String, Object>();
@Override
public Object get(String name, ObjectFactory<?> objectFactory) {
    // TODO Auto-generated method stub
    String tenantIdentifier = TenantThreadLocal.tenantThreadLocal.get()==null?"":TenantThreadLocal.tenantThreadLocal.get();
    System.out.println("tenantIdentifier in scope :"+tenantIdentifier);
    Object object=map.get(tenantIdentifier+name);

    if(object==null){
        object = objectFactory.getObject();
        System.out.println("object :"+object);

        map.put(tenantIdentifier+name, object);
    }
    System.out.println("returning object :"+object);
    return object;
}

@Override
public Object remove(String name) {
    // TODO Auto-generated method stub
    return null;
}

@Override
public void registerDestructionCallback(String name, Runnable callback) {
    // TODO Auto-generated method stub

}

@Override
public Object resolveContextualObject(String key) {
    // TODO Auto-generated method stub
    return null;
}

@Override
public String getConversationId() {
    // TODO Auto-generated method stub
    return null;
}

}