跳过可选的bean引用属性

问题描述 投票:0回答:1

我有两个同一个类的bean:

<bean id="child1" class"abc.Parent"/>

<bean id="child2" class"abc.Parent">
    <property name"service" ref="fooService"/
</beans>

类-

class Parent
{
    private FooService service;

    public void doStuff() {
        service.doFooStuff();
    }

    public FooService getService() {
        return service;
    }

    public void setService(FooService service) {
        this.service = service;
    }
}

我不想为service填充child2。是否有任何基于弹簧检查的设计模式,以确保child2除了良好的旧零检查之外没有任何反应?

java spring java-ee design-patterns javabeans
1个回答
1
投票

This看起来很相似。我想知道一个“可选的”建议是不是一个好主意 - 对我来说感觉干净和自我解释但我自己从未使用它。

© www.soinside.com 2019 - 2024. All rights reserved.