jersey-2.0 - 在基于 Jersey 的应用程序中使用 Google Guice for DI 在 weblogic 的服务器启动时出现 WELD 异常
问题描述
我使用 Weblogic 12b 作为应用服务器。我的应用程序在我的项目中使用带有 Guice3 的 Jersey 2.5.1。我有一个从 org.glassfish.jersey.server.ResourceConfig 派生的名为 Application 的类。在服务器启动时,我收到如下错误:
Caused By: org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type ServiceLocator with qualifiers @Default
at injection point [BackedAnnotatedParameter] Parameter 1 of [BackedAnnotatedConstructor] @Inject public Application(ServiceLocator)
at Application.<init>(Application.java:22)
at org.jboss.weld.bootstrap.Validator.validateInjectionPointForDeploymentProblems(Validator.java:359)
at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:281)
at org.jboss.weld.bootstrap.Validator.validateProducer(Validator.java:417)
at org.jboss.weld.injection.producer.InjectionTargetService.validateProducer(InjectionTargetService.java:36)
at org.jboss.weld.manager.InjectionTargetFactoryImpl.validate(InjectionTargetFactoryImpl.java:135)
似乎它正在用 WELD 代替 DI 的 google Guice。
我在业务层遇到了同样的问题,其中 EJB 类由 Java 类组成,它们是使用 @Inject 注入的。
我什至尝试将他的导入 @Inject 更改为谷歌注入,但异常已更改但未解决。
我尝试在 web-inf 中使用 beans.xml
@ApplicationPath("/")
public class Application extends ResourceConfig {
@Inject
public Application(final ServiceLocator serviceLocator) {
}
}
解决方案
您需要有效地禁用 CDI。
您可以通过将 WEB-INF/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_1_1.xsd"
bean-discovery-mode="none">
</beans>
注意bean-discovery-mode="none"
.
如果您的项目包含带有可能看起来 CDI bean 的类的其他 jar,那么您还需要向这些 jar 添加类似的 META-INF/beans.xml 文件。
但是,我怀疑这可能会导致其他不相关的问题。通常应用程序服务器喜欢控制类的生命周期,这包括与 JAX-RS 相关的那些。
推荐阅读
- css - 如何在小屏幕上相互叠加时使内部 div 水平居中
- datatables - 仅保留表 1 中与表 2 中的唯一值相对应的记录
- javascript - 向谷歌图表中的图例添加总数据和百分比数据
- heroku - 为什么我收到错误“bash:manage.py:找不到命令”?
- cdap - 如何预览驻留在 GCS 中的 JSON 文件中的数据?
- java - 获取文件的所有权限
- python - 如何在 python 中将多个列表合并到一个列表中:numpy.mean()
- python - 如何一次循环遍历两个列表并将一个列表中的值替换为另一个列表?
- python-3.x - 发送动态值作为参数 firestore where query
- reactjs - Redux 中的操作创建者给出错误:TypeError: Cannot read property 'filter' of undefined