关于将spring bean注入jsf bean的问题

时间:2011-05-01 13:09:23

标签: java spring jsf

将spring bean注入jsf bean时遇到了问题, 导致javax.faces.FacesException(无法实例化类),              javax.faces.el.E​​valuationException

这是我的xml文件:

文件WEB-INF / components.xml定义了spring bean

<beans>
    <bean id="rambo.api.VideoService" 
    class="rambo.impl.VideoServiceImpl">

            <!-- some properties ... -->
    </bean>
</beans>

文件WEB-INF / faces-config.xml定义jsf bean

<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:

在resourceToolExists中:videoBean使用videoService的一些方法

<h:panelGroup rendered="#{! videoBean.resourceToolExists" >
    <%@ include file="videoNoResource.jsp" %>
</h:panelGroup>

这里得到:   javax.faces.FacesException(无法实例化类rambo.impl.VideoServiceImpl),   javax.faces.el.E​​valuationException

1 个答案:

答案 0 :(得分:1)

您需要在faces-config.xml文件中配置spring elresolver。 spring elresolver将评估你的el表达并获得spring中定义的bean对象 请检查http://static.springsource.org/spring/docs/2.5.x/api/org/springframework/web/jsf/el/SpringBeanFacesELResolver.html

相关问题