0

The problem is to create n beans. The n is determined by a config. And the config is just a simple json file.

    { "bean1" : { "property" : true}, 
      "bean2" : { "property" : false}
    }

So when I parse config I get that n = 2 and create 2 beans.

There is a way to dynamically create n beans with BeanFactoryPostProcessor (how to get multiple instances of same bean in spring?)

However, In my case, I need to be able to inject config somehow, parse it and only then create n beans. I don't believe that injection is possible with BeanFactoryPostProcessor

Igor Kustov
  • 787
  • 1
  • 8
  • 21
  • Could it be possible to make a config method to takes in a list of properties, and then returns a list of beans? Then you could autowire the list? – Astrogat Oct 09 '19 at 14:19
  • I want to store properties this config in application.yml along with every other config properties. To clarify a bit I'm trying to create n jdbcTemplate instances – Igor Kustov Oct 09 '19 at 14:26
  • Why do you want to do this? You could still autowire a list of datasourceproperties, and then manually create the beans in a config method and then autowire a list of templates. – Astrogat Oct 09 '19 at 15:10

0 Answers0