【问题标题】:CDI injection doesn't inject on WebSphere 8.5 also CDI Facet causes ExceptionCDI 注入不会在 WebSphere 8.5 上注入 CDI Facet 也会导致异常
【发布时间】:2015-01-09 20:39:04
【问题描述】:

在使 CDI @Inject 工作失败后,即以下内容未注入并获得空值:

    private Standardizating standardizeService;

@Inject
public void setStandardizating(Standardizating standardizeService) {

    this.standardizeService = standardizeService;
}

要注入的类:

 @Default
 public class StandardizationService extends Service implements Standardizating {

(我有 META-INF\beans.xml)

我注意到 CDI 1.0 是我的 Eclipse/Kepler for WAS 8.5 中的一个方面。我打开了这个方面,我得到了以下异常(至少现在我可以看到某种 CDI 正在运行......我之前在日志中没有看到任何内容)。

[09/01/15 15:06:14:097 EST] 00000091 StandaloneEJB I StandaloneEJBLifeCycle   startApplication OpenWebBeans Container is starting...
[09/01/15 15:06:14:136 EST] 00000091 Helpers       W   NMSV0606E: Object is not of any type which can be bound.
[09/01/15 15:06:14:140 EST] 00000091 BeansDeployer E BeansDeployer deploy 
                             java.lang.RuntimeException: 
com.ibm.ws.naming.util.CannotBindObjectException: Object is not of any type which can be bound.
    at com.sun.jersey.server.impl.cdi.CDIExtension.initialize(CDIExtension.java:196)
    at com.sun.jersey.server.impl.cdi.CDIExtension.beforeBeanDiscovery(CDIExtension.java:297)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
    at java.lang.reflect.Method.invoke(Method.java:611)
    at org.apache.webbeans.event.ObserverMethodImpl.notify(ObserverMethodImpl.java:285)
    at org.apache.webbeans.event.NotificationManager.fireEvent(NotificationManager.java:455)
    at org.apache.webbeans.container.BeanManagerImpl.fireEvent(BeanManagerImpl.java:415)
    at org.apache.webbeans.config.BeansDeployer.fireBeforeBeanDiscoveryEvent(BeansDeployer.java:260)
    at org.apache.webbeans.config.BeansDeployer.deploy(BeansDeployer.java:159)
    at org.apache.webbeans.lifecycle.AbstractLifeCycle.startApplication(AbstractLifeCycle.java:124)
    at com.ibm.ws.webbeans.common.CommonLifeCycle.startApplication(CommonLifeCycle.java:106)
    at com.ibm.ws.webbeans.services.JCDIComponentImpl.startEJBLifeCycle(JCDIComponentImpl.java:588)
    at com.ibm.ws.webbeans.services.JCDIComponentImpl.stateChanged(JCDIComponentImpl.java:562)
    at com.ibm.ws.runtime.component.ApplicationMgrImpl.stateChanged(ApplicationMgrImpl.java:1120)
    at com.ibm.ws.runtime.component.DeployedApplicationImpl.fireDeployedObjectEvent(DeployedApplicationImpl.java:1353)
    at com.ibm.ws.runtime.component.DeployedApplicationImpl.setState(DeployedApplicationImpl.java:294)
    at com.ibm.ws.runtime.component.DeployedApplicationImpl.setState(DeployedApplicationImpl.java:289)
    at com.ibm.ws.runtime.component.DeployedApplicationImpl.start(DeployedApplicationImpl.java:978)
    at com.ibm.ws.runtime.component.ApplicationMgrImpl.startApplication(ApplicationMgrImpl.java:774)
    at com.ibm.ws.runtime.component.ApplicationMgrImpl.startApplicationDynamically(ApplicationMgrImpl.java:1374)
    at com.ibm.ws.runtime.component.ApplicationMgrImpl.start(ApplicationMgrImpl.java:2179)
    at com.ibm.ws.runtime.component.CompositionUnitMgrImpl.start(CompositionUnitMgrImpl.java:445)
    at com.ibm.ws.runtime.component.CompositionUnitImpl.start(CompositionUnitImpl.java:123)
    at com.ibm.ws.runtime.component.CompositionUnitMgrImpl.start(CompositionUnitMgrImpl.java:388)
    at com.ibm.ws.runtime.component.CompositionUnitMgrImpl.access$500(CompositionUnitMgrImpl.java:116)
    at com.ibm.ws.runtime.component.CompositionUnitMgrImpl$1.run(CompositionUnitMgrImpl.java:663)
    at com.ibm.ws.security.auth.ContextManagerImpl.runAs(ContextManagerImpl.java:5384)
    at com.ibm.ws.security.auth.ContextManagerImpl.runAsSystem(ContextManagerImpl.java:5600)
    at com.ibm.ws.security.core.SecurityContext.runAsSystem(SecurityContext.java:255)
    at com.ibm.ws.runtime.component.CompositionUnitMgrImpl.startCompositionUnit(CompositionUnitMgrImpl.java:677)
    at com.ibm.ws.runtime.component.CompositionUnitMgrImpl.startCompositionUnit(CompositionUnitMgrImpl.java:621)
    at com.ibm.ws.runtime.component.ApplicationMgrImpl.startApplication(ApplicationMgrImpl.java:1266)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
    at java.lang.reflect.Method.invoke(Method.java:611)
    at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:49)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
    at java.lang.reflect.Method.invoke(Method.java:611)
    at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:256)
    at javax.management.modelmbean.RequiredModelMBean$4.run(RequiredModelMBean.java:1148)
    at java.security.AccessController.doPrivileged(AccessController.java:252)
    at com.ibm.oti.security.CheckedAccessControlContext.securityCheck(CheckedAccessControlContext.java:30)
    at sun.misc.JavaSecurityAccessWrapper.doIntersectionPrivilege(JavaSecurityAccessWrapper.java:41)
    at javax.management.modelmbean.RequiredModelMBean.invokeMethod(RequiredModelMBean.java:1142)
    at javax.management.modelmbean.RequiredModelMBean.invoke(RequiredModelMBean.java:995)
    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:848)
    at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:774)
    at com.ibm.ws.management.AdminServiceImpl$1.run(AdminServiceImpl.java:1335)
    at com.ibm.ws.security.util.AccessController.doPrivileged(AccessController.java:118)
    at com.ibm.ws.management.AdminServiceImpl.invoke(AdminServiceImpl.java:1228)
    at com.ibm.ws.management.application.sync.StartDeploymentTask.startDeployment(StartDeploymentTask.java:247)
    at com.ibm.ws.management.application.sync.StartDeploymentTask.fullAppUpdate(StartDeploymentTask.java:119)
    at com.ibm.ws.management.application.sync.StartDeploymentTask.performTask(StartDeploymentTask.java:107)
    at com.ibm.ws.management.application.sync.AppBinaryProcessor$ExpandApp.expand(AppBinaryProcessor.java:1711)
    at com.ibm.ws.management.application.sync.AppBinaryProcessor.postProcessSynchronousExt(AppBinaryProcessor.java:751)
    at com.ibm.ws.management.bla.sync.BLABinaryProcessor.postProcess(BLABinaryProcessor.java:599)
    at com.ibm.ws.management.bla.sync.BLABinaryProcessor.onChangeCompletion(BLABinaryProcessor.java:476)
    at com.ibm.ws.management.bla.sync.BinaryProcessorWrapper.onChangeCompletion(BinaryProcessorWrapper.java:109)
    at com.ibm.ws.management.repository.FileRepository.postNotify(FileRepository.java:1924)
    at com.ibm.ws.management.repository.FileRepository.update(FileRepository.java:1433)
    at com.ibm.ws.management.repository.client.LocalConfigRepositoryClient.update(LocalConfigRepositoryClient.java:189)
    at com.ibm.ws.sm.workspace.impl.WorkSpaceMasterRepositoryAdapter.update(WorkSpaceMasterRepositoryAdapter.java:665)
    at com.ibm.ws.sm.workspace.impl.RepositoryContextImpl.update(RepositoryContextImpl.java:1998)
    at com.ibm.ws.sm.workspace.impl.RepositoryContextImpl.synch(RepositoryContextImpl.java:1946)
    at com.ibm.ws.sm.workspace.impl.WorkSpaceImpl.synch(WorkSpaceImpl.java:549)
    at com.ibm.ws.management.configservice.ConfigServiceImpl.save(ConfigServiceImpl.java:719)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
    at java.lang.reflect.Method.invoke(Method.java:611)
    at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:49)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
    at java.lang.reflect.Method.invoke(Method.java:611)
    at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:256)
    at javax.management.modelmbean.RequiredModelMBean$4.run(RequiredModelMBean.java:1148)
    at java.security.AccessController.doPrivileged(AccessController.java:252)
    at com.ibm.oti.security.CheckedAccessControlContext.securityCheck(CheckedAccessControlContext.java:30)
    at sun.misc.JavaSecurityAccessWrapper.doIntersectionPrivilege(JavaSecurityAccessWrapper.java:41)
    at javax.management.modelmbean.RequiredModelMBean.invokeMethod(RequiredModelMBean.java:1142)
    at javax.management.modelmbean.RequiredModelMBean.invoke(RequiredModelMBean.java:995)
    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:848)
    at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:774)
    at com.ibm.ws.management.AdminServiceImpl$1.run(AdminServiceImpl.java:1335)
    at com.ibm.ws.security.util.AccessController.doPrivileged(AccessController.java:118)
    at com.ibm.ws.management.AdminServiceImpl.invoke(AdminServiceImpl.java:1228)
    at com.ibm.ws.management.remote.AdminServiceForwarder.invoke(AdminServiceForwarder.java:346)
    at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1465)
    at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:85)
    at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1306)
    at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1398)
    at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:829)
    at javax.management.remote.rmi._RMIConnectionImpl_Tie.invoke(_RMIConnectionImpl_Tie.java:751)
    at javax.management.remote.rmi._RMIConnectionImpl_Tie._invoke(_RMIConnectionImpl_Tie.java:158)
    at com.ibm.CORBA.iiop.ServerDelegate.dispatchInvokeHandler(ServerDelegate.java:669)
    at com.ibm.CORBA.iiop.ServerDelegate.dispatch(ServerDelegate.java:523)
    at com.ibm.rmi.iiop.ORB.process(ORB.java:523)
    at com.ibm.CORBA.iiop.ORB.process(ORB.java:1575)
    at com.ibm.rmi.iiop.Connection.doRequestWork(Connection.java:3039)
    at com.ibm.rmi.iiop.Connection.doWork(Connection.java:2922)
    at com.ibm.rmi.iiop.WorkUnitImpl.doWork(WorkUnitImpl.java:64)
    at com.ibm.ejs.oa.pool.PooledThread.run(ThreadPool.java:118)
    at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1862)
Caused by: com.ibm.ws.naming.util.CannotBindObjectException: Object is not of any type which can be bound.
    at com.ibm.ws.naming.util.Helpers.processJavaObjectForBinding(Helpers.java:718)
    at com.ibm.ws.naming.jndicos.CNContextImpl.doRebind(CNContextImpl.java:2076)
    at com.ibm.ws.naming.jndicos.CNContextImpl.rebind(CNContextImpl.java:697)
    at com.ibm.ws.naming.jndicos.CNContextImpl.rebind(CNContextImpl.java:717)
    at com.sun.jersey.server.impl.cdi.CDIExtension.initialize(CDIExtension.java:193)
    ... 108 more

这个 Jar 中也有一些 Jersey 库用于 Jersey JAX-RS,但这个异常似乎是在引用 IBM 库。 NMSV0606E 似乎突出了对象不是 CORBA 对象、EJB、序列化对象等的问题。我只是想注入一个简单的对象,我认为我应该能够使用 CDI 来完成。它在方面说 CDI 1.0 是否支持简单的对象注入 - 我无法确定这一点。

任何帮助将不胜感激谢谢

【问题讨论】:

  • 我之前也试过这个但没有成功:@Inject private Standardizating standardizeService;
  • 让我纠正一下自己。 Jersey 库用于同一耳朵内的另一个 Jar 中的 JAX-RS 休息服务,但不在此 jar 内。

标签: cdi websphere-8 ibm-was


【解决方案1】:

您的应用可能存在两个问题:

  • 如果您想使用 Jersey 而不是默认的 WebSphere JAX-RS 提供程序,您必须将其正确配置为隔离共享库 - 检查此 - JAX-RS Jersey 2.10 support in Websphere 8
  • 如果您替换 JAX-RS 容器,很遗憾 CDI 将无法在这些类中工作。见here

当禁用 JAX-RS 运行时环境时,JAX-RS 功能不可用 可用,包括基本 JAX-RS 运行时功能、企业 JavaBeans (EJB) 运行时集成、Java 上下文和依赖项 注入 (JCDI) 运行时集成和 Servlet 3.0 Web 容器 整合。

因此,除非您真的必须使用 Jersey,否则我建议您切换到默认的 WebSphere JAX-RS 实现,那么您的 CDI 就可以工作。

【讨论】:

  • 谢谢。让我纠正一下自己。 Jersey 库用于同一耳朵内的另一个 Jar 中的 JAX-RS 休息服务,但不在此 jar 内。我只想在这个 jar 中使用默认的 WAS CDI,但它似乎不起作用。 @Inject 以 null ptrs 结束。
  • Jersey 1.17 库是我正在尝试执行 CDI 的 jar 的包含项目的一部分。这个包含的图书馆项目还有我需要的其他东西。它是由一个配置组设置的(我可能很难改变)。
  • @user1069528 如果您可以将 Jersey Libraries 提取为共享库,那么也许您可以选择性地将其仅添加到特定模块中。您还可以尝试创建单独的 EJB 模块,仅向其中添加业务库,看看它是否可以工作。我不知道你的项目结构,所以很难提出更具体的建议。
猜你喜欢
  • 1970-01-01
  • 2018-04-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-02-08
  • 2023-04-07
  • 2017-10-25
相关资源
最近更新 更多