关于将Spring bean注入jsf bean的问题 [英] A problem about injecting spring bean into jsf bean
问题描述
将spring bean注入jsf bean时遇到了一个问题, 这会导致javax.faces.FacesException(无法实例化类), javax.faces.el.EvaluationException
I met a problem when injecting spring bean into jsf bean, which causes javax.faces.FacesException(Can't instantiate class), javax.faces.el.EvaluationException
这是我的xml文件:
文件WEB-INF/components.xml定义了Spring bean
File WEB-INF/components.xml defines spring beans
<beans>
<bean id="rambo.api.VideoService"
class="rambo.impl.VideoServiceImpl">
<!-- some properties ... -->
</bean>
</beans>
文件WEB-INF/faces-config.xml定义jsf bean
File WEB-INF/faces-config.xml define jsf beans
<managed-bean>
<description>Video Home Bean</description>
<managed-bean-name>videoBean</managed-bean-name>
<managed-bean-class>rambo.tool.VideoBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
<managed-property>
<description>videoService</description>
<property-name>videoService</property-name>
<value>#{Components["rambo.api.VideoService"]}</value>
</managed-property>
<!-- Other properties -->
</managed-bean>
文件videoMain.jsp:
File videoMain.jsp:
在resourceToolExists中:videoBean使用videoService的某些方法
In resourceToolExists: the videoBean uses some methods of videoService
<h:panelGroup rendered="#{! videoBean.resourceToolExists" >
<%@ include file="videoNoResource.jsp" %>
</h:panelGroup>
在这里得到: javax.faces.FacesException(无法实例化类rambo.impl.VideoServiceImpl), javax.faces.el.EvaluationException
Here gets: javax.faces.FacesException(Can't instantiate class rambo.impl.VideoServiceImpl), javax.faces.el.EvaluationException
推荐答案
您需要在faces-config.xml文件中配置spring elresolver. spring elresolver将评估您的el express并获取spring中定义的bean对象 请检查 http://static.springsource.org/spring/docs/2.5.x/api/org/springframework/web/jsf/el/SpringBeanFacesELResolver.html
You need to config a spring elresolver in you faces-config.xml file. The spring elresolver will evaluate your el express and acquire the bean object defined in spring Please check http://static.springsource.org/spring/docs/2.5.x/api/org/springframework/web/jsf/el/SpringBeanFacesELResolver.html
这篇关于关于将Spring bean注入jsf bean的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!