【问题标题】:Spring : How to remove bean reference using listMergeDirective in listSpring:如何在列表中使用 listMergeDirective 删除 bean 引用
【发布时间】:2018-03-26 08:13:19
【问题描述】:

假设我在 spring.xml 文件中定义了一个列表。

<util:list id="addToCartMethodHooks"
                  value-type="com.test.AddToCartMethodHook"/>

AddToCartMethodHook 是一个接口,其想法是灵活地创建任意数量的实现此接口的类并将该 bean 挂钩到列表中。

我们可以使用listMergeDirective 在需要的地方添加新的 bean 定义。

<bean id="customAddToCartMethodHook" class="com.test.CustomAddToCartMethodHook" />

<bean id="customAddToCartMethodHookMergeDirective" depends-on="addToCartMethodHooks" parent="listMergeDirective">
        <property name="add" ref="customAddToCartMethodHook"/>
</bean> 

假设我想通过删除一些现有的 bean 引用来覆盖列表引用。 有什么方法可以使用 listMergeDirective 删除 bean 引用?

我还在春季检查了ListMergeDirective 课程,没有可用的删除功能。

一种方法是使用#do nothing() 删除所有代码并使用别名删除来覆盖现有类。但这最终会产生创建新类的开销。

我们怎样才能只使用 beans 删除引用?

【问题讨论】:

    标签: java spring spring-mvc


    【解决方案1】:

    AFAIK 这个功能是在 1811 版本中引入的。新的ListMergeDirective 使用remove 属性进行了增强。从那时起,我所做的通常解决方法是(仅)覆盖 bean 并从零开始提供一组新的后处理器挂钩。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-07-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-06
      • 2013-01-15
      • 1970-01-01
      • 2011-10-14
      相关资源
      最近更新 更多