Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify an @Alternative producer method in beans.xml?

Say I have:

public interface Foo {...}

public class AltProducer {
  private Foo altFoo;

  @Produces @Alternative
  public Foo getAltFoo() { return altFoo; }
}

What do I need to put in beans.xml so that my AltProducer's @Produces method will get called, instead of injecting Bar?

like image 974
Kricket Avatar asked Feb 03 '14 08:02

Kricket


1 Answers

Found it - you can just specify the whole producer class as an alternative.

@Alternative
public class AltProducer { ... }

beans.xml:

<beans>
  <alternatives>
    <class>com.package.AltProducer</class>
  </alternatives>
</beans>
like image 108
Kricket Avatar answered Oct 04 '22 22:10

Kricket