2011-10-19 9 views
2

Springで設定する必要があるプロパティを持つJSF ManagedBeanがあります。しかし、私は次のエラーを受け取ります:JSF ManagedBeanにSpring Beanをインジェクトする際のエラー

Caused by: javax.el.ELException: java.lang.IllegalArgumentException: Cannot convert [email protected] of type class $Proxy166 to class persistence.AuthDao 
at com.sun.el.ExpressionFactoryImpl.coerceToType(ExpressionFactoryImpl.java:68) 
at com.sun.faces.el.ELUtils.coerce(ELUtils.java:536) 
at com.sun.faces.mgbean.BeanBuilder$Expression.evaluate(BeanBuilder.java:592) 
at com.sun.faces.mgbean.ManagedBeanBuilder$BakedBeanProperty.set(ManagedBeanBuilder.java:606) 
... 57 more 
Caused by: java.lang.IllegalArgumentException: Cannot convert [email protected] of type class $Proxy166 to class persistence.AuthDao 
at com.sun.el.lang.ELSupport.coerceToType(ELSupport.java:397) 
at com.sun.el.ExpressionFactoryImpl.coerceToType(ExpressionFactoryImpl.java:66) 

私はELSolverをfaces-config.xmlに持っています。

<managed-bean> 
    <managed-bean-name>authController</managed-bean-name> 
    <managed-bean-class>controllers.AuthController</managed-bean-class> 
    <managed-bean-scope>session</managed-bean-scope> 
    <managed-property> 
     <property-name>authDao</property-name> 
     <value>#{authDao}</value> 
    </managed-property> 
</managed-bean> 

<application> 
    <el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver> 
</application> 

クラスを見つけることができるようですが、クラスは別の型($ Proxy166?それはどこから来るのかわからない)です。

PS:ELResolverを削除すると、そのトリックが実行されたようです。私はfaces-config.xmlのマネージドBeanを明示的に提供することがELResolverをオーバーライドすると考えました。これらの両方が共存する方法はありますか?同様に、BeanのアノテーションとXML設定の両方を提供する場合、これらのどちらかが優先されるか、またはそれらをマージする方法があります。アノテーションにいくつかのプロパティを、XMLにはいくつかのプロパティを提供しますか?

PPS:インターフェースを追加し、それらを実装するために私の現在のクラスを変更した後、私は次のエラーを取得する:

Error occurred during deployment: Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'authDao' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type '$Proxy157 implementing persistence.UserDao,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised' to required type 'persistence.UserDaoImpl' for property 'userDao'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [$Proxy157 implementing persistence.UserDao,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [persistence.UserDaoImpl] for property 'userDao': no matching editors or conversion strategy found. Please see server.log for more details.

答えて

7

これはあなたのクラスのプロキシです。あなたはインターフェイスを実装しているので、springはインターフェイスの周りにプロキシを作成しますが、具体的な型で注入しようとしています。代わりに(マネージドBeanの)インタフェースに切り替えます。

あなたが本当に具体的なクラスで注入するためにいくつかの理由で必要な場合は、あなたが@Scoped(proxyMode=ScopeProxyMode.TARGET_CLASS)

+0

を使用することができます実は、私はこのケースでインターフェイスを実装していなかった、これは、迅速なデモでした。だから、Springはデフォルトでインターフェイスを使うように強制していますか? – ustun

+0

番号。しかし、あなたのbeanは確実にインターフェースを持っています。そうしないと、$ ProxyXXを取得できません。インタフェースがない場合は、cglibを使用します – Bozho

+0

助けてくれてありがとう。私のプロジェクトでは、クラスだけでインターフェイスはありませんでした。インターフェイスを追加しても問題は解決されませんでした。上記のエラーメッセージが追加されました。 – ustun

関連する問題