2011-10-19 2 views
2

Spring에서 설정해야하는 속성을 가진 JSF ManagedBean이 있습니다.JSF ManagedBean에 Spring 빈을 주입하는 중 오류가 발생했습니다.

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) 

내가 얼굴-config.xml 파일에 ELresolver이 : 그러나, 나는 다음과 같은 오류가 발생합니다.

<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?, 그 어디에서 오는지 확실하지)이다.

추신 : ELResolver를 제거하면 트릭을 수행하는 것 같습니다. 나는 faces-config.xml에 매니지 빈을 명시 적으로 제공하는 것이 ELResolver를 오버라이드 할 것이라고 생각했다. 이 두 가지가 공존 할 수있는 방법이 있습니까? 비슷하게, 내가 선호하는 bean에 대해 annotation과 XML 설정을 둘 다 제공하거나 그들을 병합하는 방법이 있다면, annotation에 몇 가지 속성을 제공하고, 일부는 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

: 인터페이스를 추가하고이를 구현하기 위해 내 현재의 클래스를 변경 한 후, 나는 다음과 같은 오류가 발생합니다. 인터페이스를 구현하고 있으므로 스프링은 인터페이스 주위에 프록시를 만들지 만 구체적인 유형으로 삽입하려고합니다. 대신 인터페이스로 전환하십시오 (관리 Bean에서). 당신이 정말로 구체적인 클래스에 의해 주입 어떤 이유로 필요한 경우

, 당신은 사실,이 경우 인터페이스를 구현하지 않은 @Scoped(proxyMode=ScopeProxyMode.TARGET_CLASS)

+0

을 사용할 수 있습니다, 이것은 빠른 데모였다. 그렇다면 Spring은 기본적으로 인터페이스를 사용하도록 강요합니까? – ustun

+0

번호. 하지만 bean은 확실히 인터페이스를 가지고있다. 그렇지 않으면 $ ProxyXX를 얻지 못할 것이다. 인터페이스가 없다면 cglib을 사용합니다 – Bozho

+0

도움을 주셔서 감사합니다. 내 프로젝트에는 인터페이스가 없었지만 클래스 만있었습니다. 인터페이스를 추가해도 문제가 해결되지 않았으며 위에 오류 메시지가 추가되었습니다. – ustun

관련 문제