我在weblogic 12.2.1.1.0中遇到了con weld和CDI的问题,我有一个名字和代码的类:
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);
}
}
我想用jerset jax-rs注入REST服务,但在REST中我遇到了这个错误:
: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]
我在其他帖子中发现了这个错误但是解决方案,如何在lib或classpath中找到类重复,在我的情况下不正确。 其他解决方案说用户glashfish但我使用weblogic
注入是:
/**
*
* @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";
}
}
并且不运行任何想法?
答案 0 :(得分:1)
错误告诉我们,CDI在类路径上找到bo.otracosa.Database
类两次。因此,包含此类的库(jar)不止一次部署。这很难说,但常见的原因是:
bo.otracosa.Database
的库可能已经与另一个应用程序或模块一起部署(如果使用maven构建:将依赖关系的范围更改为服务器上已经存在的库provided
)答案 1 :(得分:0)
我更新了一个weblogic 12.2.1.2但有效,但是我收到了这个错误:
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
但我在cdi配置中修改了这个属性:
<?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>
最后工作