Reputation: 11
Unsatisfied dependencies error occurs with the following cords(CDI ,@Produces and @Injection) . I do not understand a reason, please tell me the cause. (Windows8, NetBeans7.4, GlassFish4.0, JDK1.7)
<beans.LoggingProducer.java>
import java.util.logging.Logger;
import javax.enterprise.inject.Produces;
import javax.enterprise.inject.spi.*;
public class LoggingProducer {
@Produces
Logger getInjectionPoint(InjectionPoint ip){ // Warnig: Unsatisfied dependencies !
String name = ip.getMember().getDeclaringClass().getName();
return Logger.getLogger( name ) ;
}
}
<beans.TopPage.java>
import java.io.Serializable;
import java.util.logging.Logger;
import javax.enterprise.context.SessionScoped;
import javax.inject.Inject;
import javax.inject.Named;
@Named
@SessionScoped
public class TopPage implements Serializable{
@Inject // Error !
Logger log;
}
<Deploy Error messages>
SEVERE: Exception during lifecycle processing
org.glassfish.deployment.common.DeploymentException:
CDI deployment failure:WELD-001408 Unsatisfied dependencies for type [Logger]
with qualifiers [@Default]
at injection point [[BackedAnnotatedField] @Inject beans.TopPage.log]
Upvotes: 1
Views: 2065
Reputation: 1324
Ok, here is your problem :)
First of all java.util.logging.Logger
has no no-arg constructor. This means that CDI cannot create its proxy object and this means you are able to produce only a @Dependent
scoped java.util.logging.Logger
bean.
The second is that you probably have bean-discovery-mode="annotated"
set in your beans.xml file. This is the default CDI configuration if you don't have a bean.xml file. This means that you must explicitly assign a scope to a class, for CDI to able to create a bean from the class. In this situation also the @Producer
methods need to specify the scope of producted bean. For example:
@Produces
@Dependent
Logger produceLogger() {
return Logger.getLogger("My awesome Logger");
}
Also the producer class has to be annotated with scope.
As an alternative you can set bean-discovery-mode="all"
but I would not recommend it.
Upvotes: 2
Reputation: 78
I would have just commented, but it seems I don't have sufficient reputation to do so. However, I don't believe the error you have included is pointing to an unsatisfied dependency on the InjectionPoint. Rather it's referring to the injection point of 'log' saying it's unable to satisfy 'log' as a dependency. Having said that I'm not sure what the problem is, the injection works for me on JBoss EAP. Do you have more error logs?
Upvotes: 0