Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Choosing a @Produces method for CDI when more than one are available

Basically, I need a way to disable one (framework supplied) @Produces method in favour of using my own @Produces method.

More specifically, I'm working with jBPM 6 and attempting to get it working correctly inside a container. The HumanTaskServiceProducer uses the drool's EnvironmentFactory, which always generates a new Environment. The code for caching the Environment in that EnvironmentFactory is commented out for some reason.

This means that jBPM picks up the JTA transaction manager rather than the Container transaction manager. I'm trying to supply my own producer for the task service that correctly sets the environment instead of using the default one.

Does anyone know of a way to specify a producer to use? In hope I tried specifying it as an @Alternative, but that doesn't seem to have worked. Either that, or a way to specify the environment on the HumanTaskServiceProducer.

like image 831
Evan Knowles Avatar asked Jan 10 '23 20:01

Evan Knowles


1 Answers

If you use CDI 1.0, alternatives don't work across different bean archives.

Otherwise (in CDI 1.1+) be careful to activate your alternative as specified here.

The best solution for you is probably to specialize your producer. You'll have to:

  • inherit the class containing the original producer method,
  • override the producer method and
  • annotated it with @Specializes.

You'll find all the info on producer specialization in the spec.

If you can't use specialization, your last solution is to create a portable extension that exclude the class containing the original producer from bean discovery (create a observer on ProcessAnnotatedType event and call the veto() method on the event) so your producer will not be in conflict with the original one.

like image 100
Antoine Sabot-Durand Avatar answered Jan 22 '23 21:01

Antoine Sabot-Durand