Null Inner Bean with Spring IoC

Posted by bruno conde on Stack Overflow See other posts from Stack Overflow or by bruno conde
Published on 2009-02-12T10:25:20Z Indexed on 2010/05/18 3:00 UTC
Read the original article Hit count: 304

Hi all.

I have a singleton bean definition like this:

<bean id="exampleBean" class="com.examples.ExampleBean">
  <property name="exampleBean2">
    <bean class="com.examples.ExampleBean2" />
  </property>
</bean>

where ExampleBean could be:

public class ExampleBean {
  private ExampleBean2 exampleBean2;

  public ExampleBean() { }

  public ExampleBean2 getExampleBean2() { return exampleBean2; }
  public void setExampleBean2(ExampleBean2 exampleBean2) { this.exampleBean2 = exampleBean2; }
}

The problem is that, in certain conditions, the com.examples.ExampleBean2 class might not exist at runtime witch will cause an error when the IoC tries to instantiate exampleBean.

What I need is to ignore this error from IoC and allow the exampleBean to be created but leaving the exampleBean2 property null.

So the question is: is this possible in any way?

Thanks for all your help.

© Stack Overflow or respective owner

Related posts about spring

Related posts about inversion-of-control