IllegalStateException:无法将LdapTemplate类型的值转换为LdapTemplate

时间:2015-05-18 21:10:02

标签: java spring jboss spring-security websphere

我正在尝试将Spring webapp从Websphere Application Server迁移到JBoss AS,但在部署时遇到了这个问题:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 
'org.springframework.security.filterChains': 
Cannot resolve reference to bean 'org.springframework.security.web.DefaultSecurityFilterChain#2' 
while setting bean property 'sourceList' with key [2]; nested exception is org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'org.springframework.security.web.DefaultSecurityFilterChain#2': 
Cannot resolve reference to bean 'preAuthenticationFilter' while setting constructor argument with key [3];  
nested exception is org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'preAuthenticationFilter': Injection of autowired dependencies failed; 
nested exception is org.springframework.beans.factory.BeanCreationException: 
Could not autowire field: private com.m.g.utils.WebUtils com.m.g.auth.PreAuthenticationFilter.webUtils;
nested exception is org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'webUtils': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: 
private com.m.g.helper.Delegate com.m.g.utils.WebUtils.Delegate; 
nested exception is org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'delegate' defined in URL [file:/workspace/Web/WebContent/WEB-INF/core-context.xml]: 
Cannot resolve reference to bean 'authenticationService' while setting bean property 'authenticationService'; 
nested exception is org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'authenticationService' defined in URL [file:/workspace/M-G-Web/WebContent/WEB-INF/core-context.xml]: Initialization of bean failed;
nested exception is org.springframework.beans.ConversionNotSupportedException: 
Failed to convert property value of type 'org.springframework.ldap.core.LdapTemplate' to required type 'org.springframework.ldap.core.LdapTemplate' for property 'ldapTemplate'; nested exception is java.lang.IllegalStateException: 
Cannot convert value of type [org.springframework.ldap.core.LdapTemplate] to required type [org.springframework.ldap.core.LdapTemplate] for property 'ldapTemplate': no matching editors or conversion strategy found

Core-context.xml的相关部分如下所示:

<bean id="authenticationService" class="com.m.g.serviceimpl.AuthenticationServiceImpl">
    <property name="wmbService" ref="wmbService" />
    <property name="authenticationDAO" ref="authenticationDAO" />
    <property name="customerDAO" ref="customerDAO" />
     <property name="ldapTemplate" ref="ldapTemplate" />
    </bean>
...
<bean id="contextSource" class="org.springframework.ldap.core.support.LdapContextSource">
    <property name="url" value="#{systemProperties['ad.write.url']}" />
    <property name="base" value="" />
    <property name="userDn" value="#{systemProperties['ad.admin.userDn']}" />
    <property name="password" value="#{systemProperties['ad.admin.password']}" />
</bean>

<bean id="ldapTemplate" class="org.springframework.ldap.core.LdapTemplate">
    <constructor-arg ref="contextSource" />
</bean>

以及AuthenticationServiceImpl.java的相关部分:

@Component("authenticationService")
public class AuthenticationServiceImpl implements IAuthenticationService {
private IWMBService wmbService;

@Autowired
private IAuthenticationDAO authenticationDAO;

@Autowired
private IServiceFactory serviceFactory;

@Autowired
private CustomerManagementDAO customerDAO;

private LdapTemplate ldapTemplate;

@Autowired
private IProperties properties;

我一直试图弄清楚为什么会出现这种错误,但我还没有找到任何有效的方法。这个完全相同的代码在Websphere下工作,所以我怀疑它就像构建路径问题。非常感谢任何帮助!

1 个答案:

答案 0 :(得分:0)

我最终搞清楚了。问题是我的项目中有两个不同版本的spring-ldap-core,这导致了两个不同的LdapTemplate实现。删除其中一个罐子解决了这个问题。