Org.springframework.beans.TypeMismatchException: Failed To Convert Property Value Of Type [$Proxy133] To Required Type

- 1 answer

In the applicationContext.xml I have a 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}" />

Now in applicationContext-acegi.xml I am referencing that ems bean:

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

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

And the

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

But I am getting this error:

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

The EMSImpl implements EMS.

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

public interface EMS extends UserDetailsService {
     //other code

How can I solve this?

Thanks and regards.



When Spring creates the transactional proxy object around EMSImpl, it makes the proxy implement the same set of interfaces at that class (i.e. EMS). The proxy will not, however, be of type EMSImpl.

In ProviderManagerFactoryBean, you need to inject type type EMS, not EMSImpl. This is also good design - it decouples your classes from each other, so that they communicate via interfaces.