spring 中配置bean的注入是<property>的name与与ref的id名需要一样吗??

[code="java"]


<bean id="fnBean" class="com.lopu.framework.modules.maintain.action.FlightNatureAction" scope="prototype">
     <property name="fnService">//此name必须是iService吗???
        <ref bean="iService" />
    </property> 
</bean>

[/code]

[code="java"]public class FlightNatureAction extends ActionSupport implements
ModelDriven {

private IService fnService;
private List<FlightNature> fnLists = new ArrayList<FlightNature>();
private FlightNature fnBean = new FlightNature();

public IService getFnService() {
    return fnService;
}

public void setFnService(IService fnService) {
    this.fnService = fnService;
}

public List<FlightNature> getFnLists() {
    return fnLists;
}

public void setFnLists(List<FlightNature> fnLists) {
    this.fnLists = fnLists;
}

@SuppressWarnings("unchecked")
public String list() throws Exception {

//如果这样写会报NPE,即fnService没注入成功,但我把整段程序中的fnService改为iService,并改下配置文件就一切正常了
this.fnLists = this.fnService.loadAll(FlightNature.class);

    return SUCCESS;
}


public FlightNature getModel() {
    return this.fnBean;
}

}[/code]

本人spring菜鸟,多多指教。。。

[quote] //此name必须是iService吗???



[/quote]

property name对应了
public void setFnService(IService fnService) {

this.fnService = fnService;

}

那么参数只要是IService类型的就OK了。。
跟下面是一样的
[code="xml"]

<bean id="fnBean" class="com.lopu.framework.modules.maintain.action.FlightNatureAction" scope="prototype">
     <property name="fnService">//此name必须是iService吗???
        <ref bean="a" />
    </property> 
</bean>

[/code]

[color=indigo][quote]

//此name必须是iService吗???





[/quote]
咱们来看你这段代码
1. 这个是干什么的? 是spring在bean的实例化过程中,把bean封装成beanwraper,然后进行统一的装配,这个name是指的是
com.lopu.framework.modules.maintain.action.FlightNatureAction里的域成员,和你配置文件里的[quote]



[/quote]没有关系,只是实例化这个bean通过action中的set方法,注入进去而已。[/color]

[color=indigo][quote]





//此name必须是iService吗???





[/quote]

你的代码改成这样也是完全可以的,只要ref的bean,和你要注入的类型一直就能注入进去[/color]