: 创建名称为 'expressionHandler' 的 bean 时出错
: Error creating bean with name 'expressionHandler'
我在使用 spring acl 时遇到错误,我只是将一些 class 范围更改为自定义范围并且在部署应用程序时我遇到了错误
: 创建名称为 'expressionHandler'
的 bean 时出错
全栈:
bean初始化失败;嵌套异常是 org.springframework.beans.factory.BeanCreationException:创建名称为 'expressionHandler' 的 bean 在 class 路径资源 [spring-security-acl.xml] 中定义时出错:无法解析对 bean 的引用 'permissionEvaluator' 同时设置 bean 属性 'permissionEvaluator';嵌套异常是 org.springframework.beans.factory.BeanCreationException:创建名称为 'permissionEvaluator' 的 bean 在 class 路径资源 [spring-security-acl.xml] 中定义时出错:无法解析对 bean 的引用 'aclService' 同时设置构造函数参数;嵌套异常是 org.springframework.beans.factory.UnsatisfiedDependencyException:在 class 路径资源 [spring-security-acl.xml] 中定义名称 'aclService' 创建 bean 时出错:通过构造函数参数表达的依赖关系不满足索引 1 类型 [org.springframework.security.acls.jdbc.LookupStrategy]:无法将类型 [org.jboss.jca.adapters.jdbc.WrapperDataSource] 的构造函数参数值转换为所需类型 [org.springframework.security.acls.jdbc.LookupStrategy]:无法转换类型 'org.jboss.jca.adapters.jdbc.WrapperDataSource' 的值到所需的类型 'org.springframework.security.acls.jdbc.LookupStrategy';嵌套异常是 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-spring-security-acl
<?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>
感谢任何帮助。
谢谢
问题出在创建租户对象时,我根据名称关键字将它放在地图中,并且由于一直使用相同的名称,我得到一种类型的对象,我通过区分地图键解决了它
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;
}
}
我在使用 spring acl 时遇到错误,我只是将一些 class 范围更改为自定义范围并且在部署应用程序时我遇到了错误 : 创建名称为 'expressionHandler'
的 bean 时出错全栈:
bean初始化失败;嵌套异常是 org.springframework.beans.factory.BeanCreationException:创建名称为 'expressionHandler' 的 bean 在 class 路径资源 [spring-security-acl.xml] 中定义时出错:无法解析对 bean 的引用 'permissionEvaluator' 同时设置 bean 属性 'permissionEvaluator';嵌套异常是 org.springframework.beans.factory.BeanCreationException:创建名称为 'permissionEvaluator' 的 bean 在 class 路径资源 [spring-security-acl.xml] 中定义时出错:无法解析对 bean 的引用 'aclService' 同时设置构造函数参数;嵌套异常是 org.springframework.beans.factory.UnsatisfiedDependencyException:在 class 路径资源 [spring-security-acl.xml] 中定义名称 'aclService' 创建 bean 时出错:通过构造函数参数表达的依赖关系不满足索引 1 类型 [org.springframework.security.acls.jdbc.LookupStrategy]:无法将类型 [org.jboss.jca.adapters.jdbc.WrapperDataSource] 的构造函数参数值转换为所需类型 [org.springframework.security.acls.jdbc.LookupStrategy]:无法转换类型 'org.jboss.jca.adapters.jdbc.WrapperDataSource' 的值到所需的类型 'org.springframework.security.acls.jdbc.LookupStrategy';嵌套异常是 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-spring-security-acl
<?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>
感谢任何帮助。 谢谢
问题出在创建租户对象时,我根据名称关键字将它放在地图中,并且由于一直使用相同的名称,我得到一种类型的对象,我通过区分地图键解决了它
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;
}
}