14.9.10

Three Approaches to Define a Bean in Spring Context XML

  • Constructor
  • Static factory method (Simple Factory Method)
  • An instance’s factory method (Factory Method)

Constructor

<bean id=”exampleBean” class=”examples.ExampleBean” />

<bean id=”anotherExample” class=”examples.ExampleBeanTwo” />

Static Factory Method

<bean id=”exampleBean” class=”examples.ExampleBean2” factory-method=”createInstance” />

An Instance’s Factory Method

<bean id=”exampleBean” factory-bean=”myFactoryBean” factory-method=”createInstance” />

No comments: