How to pass parameters dynamically to Spring beans

后端 未结 5 2127
盖世英雄少女心
盖世英雄少女心 2020-12-28 14:31

I am new to Spring.

This is the code for bean registration:

 


        
5条回答
  •  囚心锁ツ
    2020-12-28 15:03

    Perhaps letting the User_Imple be an ordinary Pojo (instead of a Spring bean) will solve your problem?

    
    
    

    Java:

    public static void main(String arg[])
    {
        ApplicationContext context =new ClassPathXmlApplicationContext("/bean.xml");
        User user = context.getBean(User.class);
    
        int id = // dynamic id
        Master_interface master = new User_Imple(id, user);
    }
    

提交回复
热议问题