【发布时间】:2021-05-03 13:59:26
【问题描述】:
在 Wildfly 20 上部署的休息端点中,我需要注入 javax.ws.rs.core.UriBuilder 类的外部非 CDI 实例。例如:
@Path("...")
public class MyResource
{
...
@Inject
private UriBuilder uriBuilder;
...
}
这里是制作人:
public class UriBuilderProducer
{
@Produces
public UriBuilder getUriBuilder()
{
return UriBuilder.fromResource(Customer.class);
}
}
beans.xml 文件内容如下:
<?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_2_0.xsd"
version="2.0" bean-discovery-mode="all">
</beans>
但是,部署失败并引发以下异常:
15:03:24,837 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-3) MSC000001: Failed to start service jboss.deployment.unit."myresource.war".WeldStartService: org.jboss.msc.service.StartException in service jboss.deployment.unit."myresource.war".WeldStartService: Failed to start service
at org.jboss.msc@1.4.11.Final//org.jboss.msc.service.ServiceControllerImpl$StartTask.execute(ServiceControllerImpl.java:1731)
at org.jboss.msc@1.4.11.Final//org.jboss.msc.service.ServiceControllerImpl$ControllerTask.run(ServiceControllerImpl.java:1559)
at org.jboss.threads@2.3.3.Final//org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
at org.jboss.threads@2.3.3.Final//org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1982)
at org.jboss.threads@2.3.3.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1486)
at org.jboss.threads@2.3.3.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1377)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type UriBuilder with qualifiers @Default
at injection point [UnbackedAnnotatedField] @Inject private ...MyResource.uriBuilder
at ...MyResource.uriBuilder(MyResource.java:0)
我错过了什么?
非常感谢您的任何帮助。
亲切的问候,
西摩
【问题讨论】:
标签: dependency-injection wildfly cdi