Reputation: 803
I have a question related to CDI warning unsatisfied or ambiguous dependencies for injection point.
The piece of code:
@Named(value = "LoginView")
@RequestScoped
public class LoginView implements Serialization {
private static final long serialVersionUID = 1L;
@Inject
private UserContext userContext;
}
@Named
@ApplicationScoped
public class UserContext implements Serialization {
public UserContext(String app, String prod, List<String>prodLines) {
this.app=app;
this.prod=prod;
this.prodLines = prodLines;
}
}
I get:
org.weld.exceptions.DeploymentExceptions: unsatisfied dependencies for type[UserContext] with qualifiers[@Inject] injection point.
If I try to remove @Inject
the deployment issue is fixed but the usercontext object is null so throws NullPointerException
. I am not using EJB so cannot use @EJB
instead of @Inject
.
Upvotes: 1
Views: 1450
Reputation: 803
The problem is resolved by creating a no-argument constructor in UserContext. There was a parameterized constructor created so the CDI injection could not call the default constructor. We have explicitly created a default no-argmument constructor therefore CDI injection worked. Created beans.xml for Fixing unsatisfied and ambiguous dependencies and added to META-INF. If you have explicitly enable an @Alternative bean that implements the bean type and has the appropriate qualifier types, using beans.xml.
Upvotes: 1