2011-05-30 81 views
0

在applicationContext.xml我有一颗豆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 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 
} 

我该如何解决这个问题?

感谢和问候。

+1

你为什么不通过'EMS'接口引用你的对象。就我所知,这就是你应该做的。 – 2011-05-30 13:54:57

+0

@Joachim绍尔你建议我在类ProviderManagerFactoryBean中使用EMS而不是EMSImpl? – 2011-05-30 13:58:45

回答

5

当Spring在EMSImpl周围创建事务代理对象时,它使代理在该类实现相同的一组接口(即EMS)。代理不会是EMSImpl类型。

ProviderManagerFactoryBean中,您需要注入型号为EMS而不是EMSImpl。这也是很好的设计 - 它将你的类彼此分开,以便它们通过接口进行通信。

相关问题