【问题标题】:Spring webflow 'Property not found' exceptionSpring webflow'找不到属性'异常
【发布时间】:2012-02-17 04:05:04
【问题描述】:

我用的是spring webflow,这是我的流程

<view-state id="welcome">
    <transition on="emailEntered" to="checkEmail"></transition>
</view-state>
<decision-state id="checkEmail">
    <if test="alta.checkEmail(requestParameters.email)"
    then="okState"
    else="errorState"/>
</decision-state>
<view-state id="okState"/>
<view-state id="errorState"/>

我在我的 servlet-context 中启用了自动扫描:

<context:component-scan base-package="com.me.myproj" />

我收到状态 checkEmail 的 org.springframework.binding.expression.PropertyNotFoundException: Property not found 错误。问题是它无法识别我的 'alta' bean,这是我的 Alta 类(放在 com.me.myproj 中):

@Component
public class Alta {
    public Alta(){
        System.out.println("constructor ok");
    }
    public boolean checkEmail(String email){

        return "my.name@email.com".equals(email);
    }

}

如果我明确创建 bean:

<bean id="alta" class="com.me.myproj.Alta"/>

然后它工作正常。因此,流上下文似乎无法识别自动扫描的组件,尽管 alta 已实例化(正如我在调试时看到的那样)。

如何避免明确声明我的流程中涉及的所有 bean?

【问题讨论】:

  • 解决了吗?解决方法是什么?
  • 不,抱歉,我没有再处理它了..

标签: spring spring-mvc spring-webflow


【解决方案1】:

当您在 XML 中显式创建 bean 时,您将使用名称“alta”(id 值)命名 bean。这就是为什么您可以执行 Alta 类中引用“alta.checkEmail(...)”的方法。

<bean id="alta" class="com.me.myproj.Alta"/>

如果您想避免 XML 声明并仅使用注释,则应在注释中指定该名称,只需将名称作为参数 [1] 传递。例如:

@Component("alta")
public class Alta {
    public Alta(){
        System.out.println("constructor ok");
    }
    public boolean checkEmail(String email){

        return "my.name@email.com".equals(email);
    }
}

希望这会有所帮助。

[1]http://static.springsource.org/spring/docs/2.5.x/api/org/springframework/stereotype/Component.html

【讨论】:

    【解决方案2】:

    你包括了吗

    <context:annotation-config/>  
    

    在您的 servlet-context.xml 中?

    【讨论】:

      猜你喜欢
      • 2012-06-01
      • 2011-09-25
      • 2013-11-04
      • 1970-01-01
      • 1970-01-01
      • 2012-11-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多