2

I followed the doc (https://docs.jboss.org/weld/reference/latest/en-US/html/injection.html) to create qualifiers, now I'm getting a deployment error in wildfly-10.1.0.Final, I red a lot of similar questions on the internet but still no clue. The code could compile and injections work well for other classes.

Here's the error:

"{
    \"WFLYCTL0080: Failed services\" => {\"jboss.deployment.unit.\\\"test.war\\\".WeldStartService\" => \"org.jboss.msc.service.StartException in service jboss.deployment.unit.\\\"test.war\\\".WeldStartService: Failed to start service
    Caused by: org.jboss.weld.exceptions.DeploymentException: Exception List with 2 exceptions:
Exception 0 :
org.jboss.weld.exceptions.DeploymentException: WELD-001409: Ambiguous dependencies for type MessageSender with qualifiers @Default
  at injection point [BackedAnnotatedField] @Inject @B private test.AccessService.messageSenderB
  at test.AccessService.MessageSenderB(AccessService.java:0)
  Possible dependencies:
  - Managed Bean [class test.messagesender.impl.MessageSenderBImpl] with qualifiers [@Any @Default],
  - Managed Bean [class test.messagesender.impl.MessageSenderAImpl] with qualifiers [@Any @Default]

Here are the classes:

@Qualifier
@Retention(RetentionPolicy.RUNTIME)
@Target({ TYPE, METHOD, PARAMETER, FIELD })
@Documented
public @interface A{}
@Qualifier
@Retention(RetentionPolicy.RUNTIME)
@Target({ TYPE, METHOD, PARAMETER, FIELD })
@Documented
public @interface B{}
public interface MessageSender {}
@Singleton
@A
public class MessageSenderAImpl implements MessageSender {}
@Singleton
@B
public class MessageSenderBImpl implements MessageSender {}
@Singleton
public class AccessService {
    @Inject
    @A
    private MessageSender messageSenderA;

    @Inject
    @B
    private MessageSender messageSenderB;

Seems the first injection worked, the second one failed. Any idea?

henriwang
  • 123
  • 1
  • 7
  • Can you make double sure that the qualifiers are part of the deployment during runtime? Because the exception suggests they aren't present/visible. – Siliarus May 22 '19 at 12:46

1 Answers1

1

I finally found it.

The stupid IDE auto imported the Qualifier class from spring framework

import org.springframework.beans.factory.annotation.Qualifier;

thought the correct one to use is

import javax.inject.Qualifier;
henriwang
  • 123
  • 1
  • 7