问题
I am trying to inject a class into my Jersey JAX-RS application using HK2, running on GlassFish.
But when I try to run my application I get this error:
com.sun.enterprise.admin.remote.RemoteFailureException: Error occurred during deployment: Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.apache.catalina.LifecycleException: org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type UsersDAO with qualifiers @Default at injection point [BackedAnnotatedParameter] Parameter 1 of [BackedAnnotatedConstructor] @Inject public com.myapp.users.resources.UserResource(UsersDAO)
Searching the web I found out that CDI in GlassFish was "competing" with HK2 for the DI, so in order to fix this, I should add this jar to my classpath (I am using Gradle):
implementation ("org.glassfish.jersey.containers.glassfish:jersey-gf-cdi:2.14")
But it doesn't work, it just gives me another cryptic error:
java.io.IOException: com.sun.enterprise.admin.remote.RemoteFailureException: Error occurred during deployment: Exception while loading the app : CDI deployment failure:WELD-001409: Ambiguous dependencies for type WebAppExceptionHolder with qualifiers @Default at injection point [UnbackedAnnotatedField] @Inject org.glassfish.jersey.gf.cdi.internal.WebAppExceptionInterceptor.store at org.glassfish.jersey.gf.cdi.internal.WebAppExceptionInterceptor.store(WebAppExceptionInterceptor.java:0) Possible dependencies: - org.glassfish.jersey.ext.cdi1x.internal.CdiComponentProvider$Hk2Bean@60e01611, - Managed Bean [class org.glassfish.jersey.gf.cdi.internal.WebAppExceptionHolder] with qualifiers [@Any @Default] . Please see server.log for more details.
Here's my AbstractBinder
implementation:
public class UsersDependencyBinder extends AbstractBinder {
private static final Logger LOG = LoggerFactory.getLogger(UsersDependencyBinder.class);
@Override
protected void configure() {
try {
// Acts as a Singleton
bind(new UsersDAO(new CachedDbConnector()));
} catch (ClassNotFoundException e) {
LOG.error("Error registering the DB Driver Manager", e);
}
}
}
And I register it using register(new UsersDependencyBinder());
.
I am not using any web.xml
, I want to be clean of *.xml
using only annotations.
来源:https://stackoverflow.com/questions/55446905/weld-001408-unsatisfied-dependencies-for-type-in-glassfish-jersey-2