2012-01-23 91 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