java - 关于jsf bean注入(inject)spring bean的一个问题

标签 java spring jsf

我在给jsf bean注入(inject)spring 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 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:

在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

最佳答案

您需要在 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

关于java - 关于jsf bean注入(inject)spring bean的一个问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5848551/

相关文章:

java - 异常 : Must start with Java agent to use InstrumentationLoadTimeWeaver. 请参阅 Spring 文档

java - 使用参数化引用类型参数模拟 Spring RestTemplate.exchange 调用

java - spring3 mvc @Valid注解找不到

java - 在本地主机错误启动 tomcat v9.0 服务器

用于:param的JSF转换器

java - 自定义日志级别

java - Hibernate 3.5.1、JPA2.0 和 MySQL - 2 个差异数据库/同一服务器内的替代行为

java - 是否有可视化工具可以检查 Java 代码库并报告包间依赖关系?

java - 从支持 bean 导航到外部 URL?

java - 如何集成 Spring 和 JSF