Search code examples
javaweblogiccdi

" WELD-001409 Ambiguous dependencies for type " in weblogic 12.2.1.1.0


i have a problem con weld and CDI in weblogic 12.2.1.1.0, i have a class with name and code:

    package bo.otracosa;

import java.lang.annotation.Retention;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.util.HashSet;
import java.util.Set;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Default;
import javax.enterprise.inject.Produces;
import javax.inject.Qualifier;
import javax.enterprise.inject.Produces;

/**
 *
 * @author jdlee
 */
@ApplicationScoped
public class Database {

    public Database() {
    }

    private Set<String> authCodes = new HashSet();
    private Set<String> tokens = new HashSet();

    public void addAuthCode(String authCode) {
        authCodes.add(authCode);
    }

    public boolean isValidAuthCode(String authCode) {
        return authCodes.contains(authCode);
    }

    public void addToken(String token) {
        tokens.add(token);
    }

    public boolean isValidToken(String token) {
        return tokens.contains(token);
    }
}

i want inject in REST service with jerset jax-rs , but in REST i got this error:

 :org.jboss.weld.exceptions.DeploymentException:WELD-001409: Ambiguous dependencies for type Database with qualifiers @Default
  at injection point [BackedAnnotatedField] @Inject public bo.sigep.modulo.api.submodulo.AuthzEndPoint.db
  at bo.sigep.modulo.api.submodulo.AuthzEndPoint.db(AuthzEndPoint.java:0)
  Possible dependencies: 
  - Managed Bean [class bo.otracosa.Database] with qualifiers [@Any @Default],
  - Managed Bean [class bo.otracosa.Database] with qualifiers [@Any @Default]

i find about this error in other post but the soluctions , how find class duplicate in lib or classpath , in my case dont correct. other solutions say that user glashfish but i use weblogic

the inject is :

/**
 *
 * @author dddd
 */
import bo.otracosa.Database;
import bo.otracosa.Otraclase;
import java.net.URI;
import java.net.URISyntaxException;
import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.apache.oltu.oauth2.as.issuer.MD5Generator;
import org.apache.oltu.oauth2.as.issuer.OAuthIssuerImpl;
import org.apache.oltu.oauth2.as.request.OAuthAuthzRequest;
import org.apache.oltu.oauth2.as.response.OAuthASResponse;
import org.apache.oltu.oauth2.common.OAuth;
import org.apache.oltu.oauth2.common.exception.OAuthProblemException;
import org.apache.oltu.oauth2.common.exception.OAuthSystemException;
import org.apache.oltu.oauth2.common.message.OAuthResponse;
import org.apache.oltu.oauth2.common.message.types.ResponseType;
import org.apache.oltu.oauth2.common.utils.OAuthUtils;

/**
 *
 * @author jdlee
 */
@Path("/authz")
public class AuthzEndPoint {


    @Inject
    public Database db;

    @GET
    public String getMethod() {

        db.isValidToken("hola");
        return "ok";

    }
}

and don't runs any idea??


Solution

  • I update a weblogic 12.2.1.2 and works but i get this error:

    Caused By: org.glassfish.hk2.api.UnsatisfiedDependencyException: There was no object available for injection at SystemInjecteeImpl(requiredType=Database,parent=AuthzEndPoint,qualifiers={},position=-1,optional=false,self=false,unqualified=null,1091065126)
    at org.jvnet.hk2.internal.ThreeThirtyResolver.resolve(ThreeThirtyResolver.java:75)
    at org.jvnet.hk2.internal.Utilities.justInject(Utilities.java:941)
    at org.jvnet.hk2.internal.ServiceLocatorImpl.inject(ServiceLocatorImpl.java:980)
    at org.glassfish.jersey.ext.cdi1x.internal.AbstractCdiBeanHk2Factory$2.getInstance(AbstractCdiBeanHk2Factory.java:142)
    at org.glassfish.jersey.ext.cdi1x.internal.AbstractCdiBeanHk2Factory._provide(AbstractCdiBeanHk2Factory.java:91)
    Truncated. see log file for complete stacktrace
    

    but i fixed with change this propertty in cdi configuration :

        <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
           bean-discovery-mode="all">
    </beans>
    

    and works finally