Java Scala Spring IoC和JSF
我有一个弹簧注射prolbem,我已经尝试解决了4天,但没有取得任何进展: 在我的spring配置中,我有:Java Scala Spring IoC和JSF,java,spring,scala,jsf,Java,Spring,Scala,Jsf,我有一个弹簧注射prolbem,我已经尝试解决了4天,但没有取得任何进展: 在我的spring配置中,我有: <bean id="applicationCache" class="domain.ui.ApplicationCacheServiceImpl"> <property name="divisionSelectOptionsCache" ref="divisionSelectOptionsCache"/> </bean> <bean i
<bean id="applicationCache" class="domain.ui.ApplicationCacheServiceImpl">
<property name="divisionSelectOptionsCache" ref="divisionSelectOptionsCache"/>
</bean>
<bean id="divisionSelectOptionsCache" class="domain.jsf.DivisionSelectOptionsCache"></bean>
divisionSelectOptions缓存.scala如下所示:
class ApplicationCacheServiceImpl extends ApplicationCacheService{
var divisionSelectOptionsCache: DivisionSelectOptionsCache = _
def setDivisionSelectOptionsCache(dsoc: DivisionSelectOptionsCache) ={
divisionSelectOptionsCache = dsoc
}
....
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
}
....
应用程序编译并生成war。但是,当我部署它时,会收到以下异常消息:
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注入属性DivisionSelectOptions缓存
对应于DivisionSelectOptions缓存
的类型这是正确的,如spring配置xml文件中所定义
Classdivision选择选项缓存
扩展
转换器
,因此应该不会出现问题
所以我被卡住了。我甚至尝试过使用SpringIOC,并使用GoogleGuice进行编译时检查,而不是部署时检查(没有xml配置文件),但这不起作用,因为应用程序依赖spring提供托管JSFbean
请帮忙,因为我马上就要告诉客户这是不可能的
谢谢使用类似于的反编译器来检查Scala编译器生成的字节码。这很可能是因为它没有按照你想的那样做。从你问这个问题开始,时间过得太久了,但我会回答的,也许这是其他人的问题 当Spring使用JDK代理时会出现此问题。正如在
JDK proxy
中一样,所有类都应该有“Interface”,而您的divisionselectoptioncache
类没有实现任何接口,那么就存在这样的问题,
有两种解决方案:
- 实现所有类的接口
- 使用
代理CGLIB
CGLib
代理,您应该在lib文件夹中添加lib并使用
<aop:aspectj-autoproxy proxy-target-class="true"/>
在
应用程序上下文中
。proxy-target类的默认值是false
,这就是JDK-proxy
只是一个小提示:您不必自己编写Java风格的getter和setter。您只需编写,例如@BeanProperty var divisionselectoptions缓存:divisionselectoptions缓存=\uu
通过谷歌搜索错误消息会得到非常相关的结果,例如,尝试spring scala api