Java CDI select alternative without priority

Viewed 304

I'm trying to replace a default implementation provided by DeltaSpike (LocaleResolver) with my own implementation via @Alternative.

@Alternative
@RequestScoped
public class ExampleLocaleResolver implements LocaleResolver {

}
<alternatives>
  <class>org.example.app.ExampleLocaleResolver</class>
</alternatives>

It seems the only way to make ExampleLocaleResolver the selected bean is by using @Priority or @Specializes.

For example, the following two works perfectly fine:

@Priority(1)
@Alternative
@RequestScoped
public class MyLocaleResolver implements LocaleResolver {

}
@Specializes
@RequestScoped
public class MyLocaleResolver extends DefaultLocaleResolver {

}

My understanding is that with CDI 1.1+, it should be possible to override beans from libraries with alternatives without any kind of hacks.

Could someone please help me understand why I'm unable to inject the @Alternative bean without the @Priorty annotation?

1 Answers
Related