class ExampleBean {
private String string;
public ExampleBean(String string) {
this.string = string;
}
}
class ExampleBeanFactory {
public static ExampleBean createExampleBean(String string) {
return new ExampleBean(string);
}
}
<bean id="exampleBean" class="...ExampleBeanFactory" scope="prototype"
factory-method="createExampleBean">
<constructor-arg value="default value"/>
</bean>
public class Main {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext(
"context.xml");
ExampleBean exampleBean =
ExampleBean)context.getBean("exampleBean",
new Object[]{"bla bla"});
exampleBean.write();
}
}
转载于:https://blog.51cto.com/vcycyv/301674