我是春天的新手。
这是bean注册的代码:
<bean id="user" class="User_Imple"> </bean>
<bean id="userdeff" class="User"> </bean>
这是我的豆类:
public class User_Imple implements Master_interface {
private int id;
private User user; // here user is another class
public User_Imple() {
super();
}
public User_Imple(int id, User user) {
super();
this.id = id;
this.user = user;
}
// some extra functions here....
}
这是我执行操作的主要方法:
public static void main(String arg[]) {
ApplicationContext context = new ClassPathXmlApplicationContext("/bean.xml");
Master_interface master = (Master_interface)context.getBean("user");
// here is my some operations..
int id = ...
User user = ...
// here is where i want to get a Spring bean
User_Imple userImpl; //want Spring-managed bean created with above params
}
现在我想用参数调用这个构造函数,这些参数是在我的主要方法中动态生成的。这就是我想要动态传递的意思——而不是静态传递,就像在我的bean.config
文件中声明的那样。