我是春天的新手
<bean id="user" class="User_Imple"> </bean> <bean id="userdeff" class="User"> </bean>
这是我的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 }
现在我想使用参数调用这个构造函数,这些参数是在我的main方法中动态生成的.这就是我想要传递的动态 – 不是静态的,就像在我的bean.config文件中声明的那样.
解决方法
请看看
Constructor injection.
另外,看看IntializingBean和BeanPostProcessor的其他生命周期拦截一个springbean.