gpt4 book ai didi

java - org.springframework.beans.TypeMismatchException : Failed to convert property value of type [$Proxy133] to required type

转载 作者:行者123 更新时间:2023-12-01 17:36:06 30 4
gpt4 key购买 nike

在 applicationContext.xml 中我有一个 bean ems:

<bean id="ems" class="info.ems.EMSImpl" init-method="init">
<property name="dao" ref="dao" />
<property name="passwordEncoder" ref="passwordEncoder" />
<property name="localeList" value="${ems.locales}" />
<property name="releaseVersion" value="${ems.version}" />
<property name="releaseTimestamp" value="${ems.timestamp}" />
<property name="emsHome" value="${ems.home}" />
</bean>

现在在 applicationContext-acegi.xml 中,我引用该 ems bean:

<bean id="authenticationManager" class="info.ems.config.ProviderManagerFactoryBean">
<property name="emsImpl" ref="ems"/>
<property name="authenticationProvider" ref="authenticationProvider"/>
</bean>

<bean id="authenticationProvider" class="org.acegisecurity.providers.dao.DaoAuthenticationProvider">
<property name="userDetailsService" ref="ems"/>
<property name="passwordEncoder" ref="passwordEncoder"/>
</bean>

还有 ProviderManagerFactoryBean.java:

public class ProviderManagerFactoryBean implements FactoryBean {

private final Logger logger = LoggerFactory.getLogger(getClass());

private EMSImpl emsImpl;
private AuthenticationProvider authenticationProvider;

public void setEmsImpl(EMSImpl emsImpl) {
this.emsImpl = emsImpl;
}

public void setAuthenticationProvider(AuthenticationProvider authenticationProvider) {
this.authenticationProvider = authenticationProvider;
}

//other code
}

但我收到此错误:

19:08:56,726 INFO  [STDOUT] 2011-05-30 19:08:56,724 [ScannerThread] ERROR [org.springframework.web.context.ContextLoader] - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'authenticationManager' defined in ServletContext resource [/WEB-INF/applicationContext-acegi.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.TypeMismatchException: Failed to convert property value of type [$Proxy133] to required type [info.ems.EMSImpl] for property 'emsImpl'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [$Proxy133] to required type [info.ems.EMSImpl] for property 'emsImpl': no matching editors or conversion strategy found

EMSImpl 实现 EMS。

@Service("emsImpl")
@Transactional(readOnly = true)
public class EMSImpl implements EMS {
//other code
}

public interface EMS extends UserDetailsService {
//other code
}

我该如何解决这个问题?

谢谢和问候。

最佳答案

当Spring围绕EMSImpl创建事务代理对象时,它使代理在该类上实现相同的接口(interface)集(即EMS)。但是,代理的类型不是EMSImpl

ProviderManagerFactoryBean中,您需要注入(inject)类型EMS,而不是EMSImpl。这也是一个很好的设计 - 它将您的类彼此解耦,以便它们通过接口(interface)进行通信。

关于java - org.springframework.beans.TypeMismatchException : Failed to convert property value of type [$Proxy133] to required type,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6177184/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com