how to instantiate more than one CDI/Weld bean for one class?

后端 未结 3 437
小蘑菇
小蘑菇 2021-01-13 00:38

In Spring it was possible to instantiate any class by defining the corresponding bean in xml conf. It was also possible to instantiate more then one bean for the same class

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-13 01:18

    You can easily use producer methods and if you have multiple instances that should be produced by a method use CDI qualifiers to distinguish different types of instances.

    Also you can use Seam Config to do it Spring way but i think producer methods are more elegant way of doing this. depending on your use case there is another option which is @Alternative .

提交回复
热议问题