在我们的一个 Web 应用程序(Struts2 + Spring 2.5 + iBatis)中,我们使用以下 MVC 结构。
ActionClass <---> ServiceInterface <---> ServiceImplementationClass <---> DAOClass <---> DB
所有这些 java 类都是使用 Spring 实例化的。使用 DI 技术将 Service 类注入到 Struts2 Action 类中。我对 spring 应用程序上下文 xml 中使用的范围属性有疑问。
以下是来自我们的 Spring applicationcontext.xml 的示例条目。
我想了解
一个。从并发的角度来看,仅将操作类作为 Prototype 并将其余层类作为 Singleton 是否正确?
湾。从内存泄漏的角度来看,定义范围是否有任何指导方针?
<bean id="commonAction" scope="prototype"
class="com.xyz.action.CommonAction">
<property name="commonService" ref="commonService" />
</bean>
<bean id="commonService" class="com.xyz.service.impl.CommonServiceImpl">
<property name="commonDao" ref="commonDao" />
</bean>
<bean id="commonDao" class="com.xyz.dao.impl.CommonDAOImpl">
<property name="sqlMapClient" ref="sqlMap" />
</bean>
这是我们的 Struts xml 条目
<struts>
<constant name="struts.enable.DynamicMethodInvocation" value="false"></constant>
<constant name="struts.devMode" value="true" />
<constant name="struts.objectFactory" value="spring" />
<package name="default" namespace="/" extends="struts-default">
感谢您对此的回应。