Spring webflow“未找到属性”例外
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否包含
在 servlet-context.xml 中?
Did you include
in your servlet-context.xml?
当您在 XML 中显式创建 bean 时,您将使用名称“alta”(id 值)来命名该 bean。这就是为什么您可以引用“alta.checkEmail(...)”执行 Alta 类中的方法。
如果您想避免 XML 声明并仅使用注释,则应通过仅将名称作为参数传递来在注释中指定该名称 [1]。例如:
希望这有帮助。
[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(...)".
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:
Hope this helps.
[1] http://static.springsource.org/spring/docs/2.5.x/api/org/springframework/stereotype/Component.html