0

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?

Farrukh Chishti
  • 7,652
  • 10
  • 36
  • 60

1 Answers1

1

This looks similar. I am wondering if an "optional" suggestion would be a good idea - feels clean and self explanatory to me but I have never use it myself.

komfitura
  • 53
  • 4