【问题标题】:IllegalStateException: Cannot convert value of type LdapTemplate to LdapTemplateIllegalStateException:无法将 LdapTemplate 类型的值转换为 LdapTemplate
【发布时间】:2015-05-18 21:10:02
【问题描述】:

我正在尝试将 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 下工作,所以我怀疑它类似于构建路径问题。非常感谢任何帮助!

【问题讨论】:

  • 您确定要向我们展示所有相关内容吗?我没有在您的 XML 中看到名为 ldapTemplate 的类型为 LdapTemplate 的属性。
  • 很好,我错过了 XML 文件中实际的 ldapTemplate bean 定义。我在上面更新了它。
  • 你误会我了。该错误表示 Spring 无法创建 authenticationService bean,因为它的 LdapTemplate 类型的属性之一有问题。您的 XML 没有定义 LdapTemplate 类型的 property,所以我看不出这怎么可能。
  • 另外,为什么你同时拥有authenticationService bean 的 XML 声明和 authenticationService bean 的 Java @Component 声明?
  • 我太傻了,我错误地粘贴了 XML 的关键部分。你是对的,它确实被定义为一个属性。同样对于 bean 声明,我最初并没有编写代码库的这个特定部分,所以我不确定为什么会做出这个决定。

标签: java spring jboss spring-security websphere


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-09
    • 1970-01-01
    • 1970-01-01
    • 2016-12-07
    • 1970-01-01
    相关资源
    最近更新 更多