WELD-001408 Unsatisfied dependencies for type [LdapService] with qualifiers [@Named] at injection point

Cosas picture Cosas · Nov 18, 2014 · Viewed 30.9k times · Source

Hello I'm trying to deploy an EAR to my Weblogic server 12c (12.1.3) without success.

My LdapService class is a Stateless EJB with default no args constructor (This project is an ejb package)

@Stateless
public class LdapService {

@Inject
public LdapService() {

} ...

I'm trying to inject it to another class like:

public class UserService {

private static final Logger logger = LoggerFactory.getLogger(UserService.class.getCanonicalName());
@Inject
private LdapService registerService;

@EJB(beanName = "Janus-session-1.0.jar#UserBean")
private TUserBean userBean;

...}

The bean annotated with @EJB it's recognized by the CDI, but the injection point throws me this error about the @Inject:

Deployment failed. The message was: org.jboss.weld.exceptions.DeploymentException: WELD-001409 Ambiguous dependencies for type [LdapService] with qualifiers [@Default] at injection point [[field] @Inject net.ab4cus.project.business.TransactionService.registerService]. Possible dependencies [[Session bean [class net.ab4cus.project.auth.LdapService with qualifiers [@Any @Default]; local interfaces are [LdapService]]

If in LdapService use @Named("LdapService") and then at the injection point use:

@Inject @Named("LdapService") private LdapService registerService;

Then I got this error:

Deployment failed. The message was: org.jboss.weld.exceptions.DeploymentException: WELD-001408 Unsatisfied dependencies for type [LdapService] with qualifiers [@Named] at injection point [[field] @Inject @Named net.ab4cus.project.business.UserService.registerService]

How do I can solve this error and remove the ambiguity? or what is the correct way to do @Inject to other beans?

Thank You.

EDIT----------------------------------------------------------------------------------------------

I managed to deploy the EAR, but now have other errors involving the CDI.

My EAR contents are: EJB module (with the beans and all the business logic) and two WAR's (One for WebServices and one for a Web FronEnd using Vaadin).

The WebServices are RESTFull, and no matter what WS I try to consume, get always this error:

java.lang.NullPointerException
at com.sun.jersey.server.impl.cdi.CDIComponentProviderFactory.<init>(CDIComponentProviderFactory.java:94)
at com.sun.jersey.server.impl.cdi.CDIComponentProviderFactoryInitializer.initialize(CDIComponentProviderFactoryInitializer.java:76)
at com.sun.jersey.spi.container.servlet.WebComponent.configure(WebComponent.java:572)
at com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.configure(ServletContainer.java:314)
at com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:604)
Truncated. see log file for complete stacktrace

If I try with the frontend, any time a bean is accesed I get this error (for each bean):

SEVERE: 
java.lang.IllegalArgumentException: Can not set net.ab4cus.project.session.TUserBean field net.ab4cus.project.business.UserService.userBean to net.ab4cus.project.session.UserBean_o7pydo_NoIntfViewImpl
    at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:164)
    at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:168)

I'm trying to resolve this, but for now have no clue :/

Answer

Cosas picture Cosas · Nov 24, 2014

The solution for my first error was:

-Removing the @Stateless and @Inject from LdapService and the default constructor

public class LdapService {

}...

-Create an Interface for LdapService and @Inject this interface to UserService

public class UserService {

private static final Logger logger = LoggerFactory.getLogger(UserService.class.getCanonicalName());
@Inject
private LdapServiceInterface registerService;

@EJB(beanName = "Janus-session-1.0.jar#UserBean")
private TUserBean userBean;

...}