JSF

时间:2017-10-01 17:07:19

标签: spring spring-mvc jsf

我们正在使用spring 3.1.1和mojarra 2.1.29-08将应用程序从jsf 1.2转换为jsf2在wildfly 10中。这样做,我们得到的范围错误如下:

The scope of the object referenced by expression #{configConstant}, request, is shorter than the referring managed beans (UserSearchBean) scope of view

在faces-config.xml中,我们定义UserSearchBean,如:

    <managed-bean>
    <managed-bean-name>UserSearchBean</managed-bean-name>
    <managed-bean-class>com.mycompany.UserSearchBean</managed-bean-class>
    <managed-bean-scope>view</managed-bean-scope>
    <managed-property>
        <property-name>configConstant</property-name>
        <value>#{configConstant}</value>
    </managed-property>
</managed-bean>

在applicationContext.xml中我们有:

<import resource="../aaconfig.xml" ></import>

在那个aaconfig文件中我们有:

<bean id="configConstant" scope="singleton"
    class="com.mycompany.ConfigConstant" >
    <property name="fileName">
        <value>config.xml</value>
    </property>
    <property name="logofilename" value="${config.logofilename}" />
</bean>

从我们阅读的内容来看,单例范围应该是全局的,但来自wildfly的错误消息则另有说明。我们在web.xml中有这些

      <listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
 </listener>
  <context-param>
 <param-name>contextConfigLocation</param-name>
 <param-value>classpath:applicationContext.xml</param-value>
 </context-param>
 <servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<async-supported>true</async-supported>
</servlet>
 <servlet>
 <servlet-name>accessaudit</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>

我刚刚意识到其他bean工作得很好,就像这个一样。它注入正确范围的罚款。我能立即看到的唯一不同是configConstant具有从属性文件中读取的属性。

<bean id="userManager" class="com.mycompany.UserManager">
    <property name="userManagerDAO">
       <ref bean="userManagerDAOProxy" />
    </property>

关于什么是问题或从哪里开始寻找的想法?

谢谢!

1 个答案:

答案 0 :(得分:0)

我找到了,但不知道为什么。我有这个:

<bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="viewClass"><value>org.springframework.web.servlet.view.JstlView</value></property>
    <property name="prefix"><value>/jsp/</value></property>
    <property name="suffix"><value>.jsp</value></property>
    <property name="exposedContextBeanNames">
        <list>
            <value>configConstant</value>
        </list>
    </property>
</bean>

当我删除exposedContextBeanNames部分时,它不再提供错误。我知道我们确实有一些使用configConstant变量的旧jsp文件。暴露中的某些东西必须改变范围,任何人都知道为什么或如何实现相同的goad?