简体   繁体   English

具有xml配置的构造函数注入的Spring装饰器

[英]Spring decorator with constructor injection with xml configuration

I am using the decorator patter in my application and would like to configure it in xml spring configuration. 我在应用程序中使用装饰器模式,并希望在xml spring配置中对其进行配置。

Lets say I have a class someService and a decorator called someServiceDecorator . 可以说我有一个class someService和一个称为someServiceDecorator的装饰器。 Both services have multiple dependencies. 两种服务都具有多个依赖性。

I tried this: <beans:bean id="someService" autowire="constructor" class="com.my.someService" /> <beans:bean id="someServiceDecorator" autowire="constructor" primary="true" class="com.my.someServiceDecorator" /> 我尝试了此操作: <beans:bean id="someService" autowire="constructor" class="com.my.someService" /> <beans:bean id="someServiceDecorator" autowire="constructor" primary="true" class="com.my.someServiceDecorator" />

Without success. 没有成功。 I think it is strange I can't find any examples of the decorator pattern for spring with xml configuration. 我觉得很奇怪,找不到带有xml配置的spring装饰器模式的示例。

Actually, I just tried this and this worked. 实际上,我只是尝试了这一点而已。

<beans:bean id="someServiceDecorator" autowire="constructor" class="com.my.someServiceDecorator">
    <constructor-arg>
        <beans:bean autowire="constructor" class="com.my.someService" />
    </constructor-arg>
</beans:bean>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM