【问题标题】:Spring scope not recognized by JSFJSF 无法识别 Spring 范围
【发布时间】:2017-10-01 17:07:18
【问题描述】:

我们正在使用 spring 3.1.1 和 mojarra 2.1.29-08 将应用程序从 jsf 1.2 转换为 Wildfly 10 中的 jsf2。这样做时,我们会收到一个范围错误,例如:

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>

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

谢谢!

【问题讨论】:

标签: spring spring-mvc jsf


【解决方案1】:

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

<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 部分时,它不再给出错误。我知道我们确实有一些旧的 jsp 文件使用来自 configConstant 的变量。曝光中的某些东西一定改变了范围,有人知道为什么或如何达到同样的目的吗?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-10-16
    • 1970-01-01
    • 2011-10-16
    • 2011-08-15
    • 2019-01-21
    • 2012-10-11
    • 2014-09-14
    相关资源
    最近更新 更多