search

Home  >  Q&A  >  body text

java - How does Spring create different instances of a specific type of bean based on the parameters passed in at startup and call these instances in subsequent business?

Note that instead of simply configuring the bean scope into multiple instances, you need to create different instances according to different parameters at startup. These created instances need to be called in subsequent business Example.
My current idea is to use factoryBean to proxy the abstracted parent class, and then configure the concretely implemented subclasses into different instances in the xml file. However, in this way, the parameters may be dynamically read from the database. Second, the number of generated instances cannot be determined, so I don’t know if there is any other way?

学习ing学习ing2719 days ago755

reply all(1)I'll reply

  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-06-23 09:14:52

    You can read the database at startup, then put the multiple generated instances into a HashMap, and then provide a method to get the instance objects based on the type. No need to make it @Bean

    reply
    0
  • Cancelreply