mardi 9 avril 2019

Skip optional bean reference property

I have two beans for the same class:

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

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

Class-

class Parent
{
    private FooService service;

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

    public FooService getService() {
        return service;
    }

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

I don't want to populate service for child2. Is there any design pattern of spring based check to ensure that nothing happens for child2 apart from the good old null check?

Aucun commentaire:

Enregistrer un commentaire