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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With