Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unsatisfied dependencies for type X with qualifiers @Default

I'm trying to inject an object of a given type (Greeter) on an EJB running inside Wildfly 8.2. However, the deployment always fails with the message

Unsatisfied dependencies for type Greeter with qualifiers @Default

I tried to annotate both the GreeterImpl and the injection point with @Default but that didn't also work. Am I missing something here?

My Greeter interface:

public interface Greeter {
    public void sayHi();
}

My GreeterImpl class (the only one that implements Greeter):

public class GreeterImpl implements Greeter {
    private static final Logger LOGGER = LoggerFactory.getLogger(GreeterImpl.class);

    @Override
    public void sayHi() {
        LOGGER.info("Hi!");
    }
}

My ScheduledGreeter EJB:

@Stateless
public class ScheduledGreeter {
    @Inject
    private Greeter greeter;

    @Schedule(second = "*/15", minute = "*", hour = "*")
    public void sayHi() {
        greeter.sayHi();
    }
}

Am I missing something about CDI here? Do I need a beans.xml at META-INF for this to work?

Edit: I'm deploying this as war to Wildfly, if that even matters.

like image 937
Martin Avatar asked Dec 30 '14 13:12

Martin


1 Answers

In Java EE 7, the default scanning for JARs/WARs is annotated, meaning that if you don't have a beans.xml that specifies the scan mode, it will default to annotated based scanning.

Your class, GreeterImpl has no bean defining annotations on it - no scopes particularly. You can override this by adding a beans.xml or by adding @Dependent (or other scope) to your GreeterImpl

like image 170
John Ament Avatar answered Nov 05 '22 02:11

John Ament