1

我有一个弹簧注射问题,我已经尝试解决 4 天但没有得到任何结果:

在我的春季配置中,我有:

<bean id="applicationCache" class="domain.ui.ApplicationCacheServiceImpl">
    <property name="divisionSelectOptionsCache" ref="divisionSelectOptionsCache"/>
</bean>

<bean id="divisionSelectOptionsCache" class="domain.jsf.DivisionSelectOptionsCache"></bean>

ApplicationCacheServiceImpl.scala 看起来像这样:

class ApplicationCacheServiceImpl extends ApplicationCacheService{
   var divisionSelectOptionsCache: DivisionSelectOptionsCache = _

   def setDivisionSelectOptionsCache(dsoc: DivisionSelectOptionsCache) ={
     divisionSelectOptionsCache = dsoc
   }
 ....

DivisionSelectOptionsCache.scala 看起来像这样:

class DivisionSelectOptionsCache extends Converter{
   val options = mutable.Map[String, DivisionSelectOption]()
   var em: EntityManager = _

   // Just left this in case its  relevant. Throws no errors though
   @PersistenceContext
   def setEntityManager(entManager: EntityManager) = {
      em = entManager
   }
   ....

应用程序编译并构建了一个战争。但是,当我部署它时,我得到以下异常消息:

INFO: Initializing Spring root WebApplicationContext
Jan 18, 2013 7:56:17 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'applicationCache' defined in class path resource 
applicationPersistence.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: 
Failed to convert property value of type '$Proxy15 implementing javax.faces.convert.Converter,org.springframework.aop.SpringProxy,
org.springframework.aop.framework.Advised' to required type 'com.domain.jsf.DivisionSelectOptionsCache' 
for property 'divisionSelectOptionsCache'; nested exception is java.lang.IllegalStateException: 
Cannot convert value of type [$Proxy15 implementing javax.faces.convert.Converter,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised]
 to required type [com.domain.jsf.DivisionSelectOptionsCache] for property 'divisionSelectOptionsCache': no matching editors or conversion strategy found
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
  at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
  at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
 .....
Caused by: org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type '$Proxy15 implementing javax.faces.convert.Converter,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised' to required type 'com.domain.jsf.DivisionSelectOptionsCache' for property 'divisionSelectOptionsCache'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [$Proxy15 implementing javax.faces.convert.Converter,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [com.domain.jsf.DivisionSelectOptionsCache] for property 'divisionSelectOptionsCache': no matching editors or conversion strategy found
  at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:485)
  at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:516)
....
Caused by: java.lang.IllegalStateException: Cannot convert value of type [$Proxy15 implementing javax.faces.convert.Converter,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [com.domain.jsf.DivisionSelectOptionsCache] for property 'divisionSelectOptionsCache': no matching editors or conversion strategy found
  at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:247)
  at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:470)
  ... 31 more

Jan 18, 2013 7:56:20 PM org.apache.catalina.core.StandardContext filterStop
FINE: Stopping filters

所以: ApplicationCacheServiceImpl正在寻找 spring 来注入属性divisionSelectOptionsCache,对应的类型DivisionSelectOptionsCache是正确的,并且在 spring config xml 文件中定义。

上课DivisionSelectOptionsCache extends Converter,所以那里应该没有问题。

所以我被困住了。我什至尝试取出 spring IoC 并使用 google Guice 进行编译时间检查而不是部署时间检查(没有 xml 配置文件),但这不起作用,因为应用程序依赖于 Spring 来提供托管 jsf bean。

请帮忙,因为我快要告诉客户它无法完成。

谢谢

4

2 回答 2

0

使用类似http://java.decompiler.free.fr/的反编译器来检查 Scala 编译器生成的字节码。很可能它没有按照你的想法做。

于 2013-01-19T23:04:55.380 回答
0

从你问这个问题到现在已经过去了太多时间,但我会回答它,也许这是别人的问题,

这个问题出现在 Spring 使用JDK proxy. 因为JDK proxy所有的类都应该有“接口”,而你的DivisionSelectOptionsCache类没有实现任何接口,那么就会出现这样的问题,有两种解决方案:

  • 为所有类实现接口

  • 使用CGLIB代理

为了使用CGLib代理,您应该在 lib 文件夹中添加 lib 并使用

<aop:aspectj-autoproxy proxy-target-class="true"/>

application-context. 的默认值为,proxy-target-class即。falseJDK proxy

于 2015-03-10T05:25:21.670 回答