struts 2动作类实例变量初始化

我目前正在使用现有项目。它正在使用Struts 2 + Spring 2.5。 有一个动作类,我们称之为ActionA.java,其中有一个实例变量,它是一个服务接口,如, class ActionA { //变量 受保护的ServiceAInterface serviceA; //动作方法,利用serviceA方法 } 在spring bean定义中,有一个定义,如< bean id =“serviceA”class =“com.company.serviceAImplementationClass”/> 我没有找到与serviceA变量的初始化相关的其他任何地方,并且真的想知道,哪个部分找到了这个变量的正确实现类,并初始化它? 这真让我困惑。感谢任何启示。 成龙     
已邀请:
一种方法是将服务bean定义为
<bean id="serviceA" class="com.company.serviceAImplementationClass"/>

<bean id="actionClassA" class="com.company.ActionA">
   <property name="serviceA" ref="serviceA"/>
</bean>
然后在你的课堂上,为你的服务类编写setter和getter。
class ActionA{

//variables

protected ServiceAInterface serviceA;

//action methods, utilizing serviceA methods

public ServiceAInterface getServiceA() {
   return this.serviceA;
}

public void setServiceA(ServiceAInterface serviceA)
   this.serviceA = serviceA;
}

}
而已。服务类bean将在应用程序启动期间由spring启动,其引用将分配给您的操作类。     

要回复问题请先登录注册