Spring webflow“未找到属性”例外

发布于 2024-12-28 21:49:49 字数 1274 浏览 1 评论 0原文

我正在使用 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:component-scan base-package="com.me.myproj" />

我收到状态 checkEmail 的 org.springframework.binding.expression.PropertyNotFoundException:未找到属性 错误。问题是它无法识别我的“alta”bean,这是我的 Alta 类(放置在 com.me.myproj 中):

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

        return "[email protected]".equals(email);
    }

}

如果我显式创建该 bean:

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

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

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

I am using spring webflow, this is my flow

<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"/>

I have enabled auto-scanning in my servlet-context:

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

I get a org.springframework.binding.expression.PropertyNotFoundException: Property not found error for state checkEmail. The problem is that it doesn't recognize my 'alta' bean, this is my Alta class (placed in com.me.myproj):

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

        return "[email protected]".equals(email);
    }

}

If I explicitly create the bean:

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

Then it works fine. So it seems that flow context doesn't recognize auto-scanned components, although alta is instanciated (as I saw when I debugged).

What can I do to avoid declaring explictly all beans involved in my flow?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

染柒℉ 2025-01-04 21:49:49

您是否包含

<context:annotation-config/>  

在 servlet-context.xml 中?

Did you include

<context:annotation-config/>  

in your servlet-context.xml?

素染倾城色 2025-01-04 21:49:49

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

<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 "[email protected]".equals(email);
    }
}

希望这有帮助。

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

When you explicitly create the bean in the XML you are naming the bean with name "alta" (id value). That is why you can execute methods from class Alta refering to "alta.checkEmail(...)".

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

If you want to avoid XML declaration and use annotations only, you should specify that name in the annotation by just passing the name as argument [1]. For example:

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

        return "[email protected]".equals(email);
    }
}

Hope this helps.

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文