2012-01-23 93 views
3

我使用的春天的Webflow,这是我的流程春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" /> 

我得到一个org.springframework.binding.expression.PropertyNotFoundException:未找到属性错误为状态checkEmail。问题是,它不承认我的“阿尔塔”豆,这是我的阿尔塔类(放在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是instanciated(就像我在调试时看到的那样)。

我该怎么做才能避免显式声明所有涉及到我的流程的bean?

+0

它解决了吗?什么是修复? –

+0

不,对不起,我没有工作了.. – de3

回答

0

是否包含

<context:annotation-config/> 

在servlet-context.xml的?

+0

我试过了,但没有奏效 – de3

0

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

希望这会有所帮助。

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