确保
<context:component-scan.../>两个xml配置中都没有完全重复的元素。如果有此功能,则基本上是在复制所有bean实例。您最初拥有的所有豆都由装载,
ContextLoaderListener由于存在,这些代理被代理了
<tx:annotation-driven />。
现在,如果您
<context:component-scan .../>在payment-
servlet.xml中具有相同的名称,则将再次扫描所有创建另一个实例的bean,但是由于不存在该事实,因此不会
<tx:annotation-driven/>对其进行代理并且不会应用任何事务。
现在发生的事情是,一旦您需要一个带
@Service注释的bean,
DispatcherServlet它就会首先看起来自己,
ApplicationContext以查看是否有bean可以满足其需求。如果有的话(当前情况)将要使用(如果没有),它将查询父上下文(由加载的上下文
ContextLoaderListener)。
你需要做的是配置
ContextLoaderListener扫描都 但
@Controller注释豆类和
DispatcherServlet扫描 仅
用于
@Controller注解的bean。可以通过
<context:component-scan .../>正确配置来完成。
applicationContext.xml
<context:component-scan base-package="com.appn.payment"> <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" /></context:component-scan>
付款servlet.xml
<context:component-scan base-package="com.appn.payment" use-default-filters="false"> <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" /></context:component-scan>
这将为您提供事务,并且仅提供bean的单个实例。您应该
<tx:annotation-driven />从Payment-
servlet.xml文件中删除。
JIRA尚有一个未解决的问题,可以将其包含在参考指南中。spring社区论坛中的一个线程对此进行了解释。



