Spring有一个getBean重载,它接受参数。 如何将这些参数传递给Bean的@Bean创建函数?
class Person
{
String name;
Person(String name) {
this.name = name;
}
}
public class SpringAnnotationmain {
public static void main(String[] args) {
AnnotationconfigApplicationContext ctx = new AnnotationconfigApplicationContext(SpringAnnotationmain.class);
Person x = ctx.getBean(Person.class,new Object[] {"Alice"});
System.out.println(x.name);
ctx.close();
}
}