0

After failure getting a CDI @Inject to work i.e, the following was not injected and got a null :

    private Standardizating standardizeService;

@Inject
public void setStandardizating(Standardizating standardizeService) {

    this.standardizeService = standardizeService;
}

Class to inject :

 @Default
 public class StandardizationService extends Service implements Standardizating {

(I have META-INF\beans.xml)

I noticed that CDI 1.0 is a facet in my Eclipse/Kepler for WAS 8.5. I turned the facet on and I got the following exception (at least now I can see that some sort of CDI is operative ... I didn't see anything in the logs earlier).

[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

There are some Jersey libraries used in this Jar as well for Jersey JAX-RS but this exception seems to be referencing IBM libraries. NMSV0606E seems to be highlighing a problem with the object not being a CORBA object, EJB, serialized object etc. I'm just trying to inject a simple object which I think I should be able to do with CDI. It says in the facet CDI 1.0 Does that support simple object injection -- I'm haven't been able to determine this.

Any help would be appreciated Thanks

Gas
  • 17,601
  • 4
  • 46
  • 93
user1069528
  • 618
  • 1
  • 13
  • 29
  • I also tried this earlier without success: @Inject private Standardizating standardizeService; – user1069528 Jan 09 '15 at 20:59
  • Let me correct myself. Jersey libraries are used for JAX-RS rest services in another Jar within the same ear but not within this jar. – user1069528 Jan 12 '15 at 14:19

1 Answers1

0

There might be two issues with your app:

  • If you want to use Jersey instead of default WebSphere JAX-RS provider you have to correctly configure it as isolated shared library - check this - JAX-RS Jersey 2.10 support in Websphere 8
  • If you replace the JAX-RS container, unfortunately CDI will not work in these classess. See here.

When disabling the JAX-RS runtime environment, JAX-RS features are not available, including base JAX-RS runtime capabilities, Enterprise JavaBeans (EJB) runtime integration, Java Contexts and Dependency Injection (JCDI) runtime integration, and Servlet 3.0 web container integration.

So unless you really have to use Jersey, I'd recommend to switching to defalut WebSphere JAX-RS implementation, then your CDI will work.

Community
  • 1
  • 1
Gas
  • 17,601
  • 4
  • 46
  • 93
  • Thanks. Let me correct myself. Jersey libraries are used for JAX-RS rest services in another Jar within the same ear but not within this jar. I want to just use the default WAS CDI within this jar but it doesn't seem to be working. @Inject end up with null ptrs. – user1069528 Jan 12 '15 at 14:21
  • Jersey 1.17 libraries are part of an included project for the jar where I'm trying to do CDI. this included library project has other things I need. It is setup by a config group (might be difficult for me to change). – user1069528 Jan 12 '15 at 14:25
  • @user1069528 If you could extract Jersey Libraries as shared library, then maybe you could be able to selectively add it only to specific modules. You could also try to create separate EJB module, add only business libraries to it and see if it would work. I don't know your project structure, so it's hard to suggest something more specific. – Gas Jan 12 '15 at 15:49