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

后端 未结 3 452
小蘑菇
小蘑菇 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条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-13 01:10

    Two options as far as I can see:

    • Without further knowledge of your usecase, I assume that you either want to provide some alternative implementation for (mock-) testing or configuration issues (say another PaymentProvider for a OrderService). This is supported by the spec itself, have a look at @Alternative here (and don't repeat my initial mistake and forget to activate alternatives in beans.xml)

    • To get a Spring-style XML-configuration, you can use Seam 3 Config, which provides XML-configuration just as described. BTW, this has been a part of JSR 299, but has been removed from the spec for whatever reason.

提交回复
热议问题