[cdi-dev] Optional bean support in CDI : @Requires annotation

Adrian Gonzalez adr_gonzalez at yahoo.fr
Wed Jan 16 11:21:22 EST 2013


Hello,

If there's a better mailing list than cdi-dev for this kind of question, just let me know and sorry :)

A question about https://issues.jboss.org/browse/CDI-225.

I have a CDI jar using an optional jar. And CDI impl I use log an error [1] (the bean is then ignore and my webapp functions normally). 
Problem is I have a lot of errors in console and I don't want to tell my users to change logging configuration each time they use my lib.

@Requires(com.filenet.api.constants.Cardinality.class.getName()) won't be available in CDI 1.1 what are my options ?

If I understood correctly :
 1. Do nothing and hope cdi impl just log a warning and ignore the bean (this is the case for OWB and Weld)
     -> this will be non-portable of course.
 2. Change the current packaging
      -> I will need to package each optional functionnality in its own jar in this case.
 3. Create my own @Requires annotation and the corresponding extension
      -> I don't think it's doable since CDI impl will have to build the AnnotatedType before my extension can veto or add @Veto (and even then adding @Veto will be too late)

No more options ?

If not and 2 is the only working portable solution, is it possible to reopen CDI-225 ?
It's quite strange IMO to have CDI force a packaging decision.
Some libraries are not packaged with this logic (i.e. spring-orm has a lot of optionnal dependencies - i.e for hibernate 3, hibernate 4, jdo, jpa).

Thanks for your help and sorry for the long mail


[1]
Error with Weld (JBoss 7.1.0)
15:28:18,490 INFO 
[org.jboss.weld.ClassLoading] (MSC service thread 1-4) catching: org.jboss.weld.resources.spi.ResourceLoadingException: Error loading
class com.natixis.sphinx.jsf.filenet.ged.SessionMetadata$PropertyMetadata
      at
org.jboss.weld.resources.ClassTransformer.loadClass(ClassTransformer.java:152)
[weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
      at
org.jboss.weld.bootstrap.BeanDeployer.addClass(BeanDeployer.java:86)
[weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
      at
org.jboss.weld.bootstrap.BeanDeployer.addClasses(BeanDeployer.java:115)
[weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
      at
org.jboss.weld.bootstrap.BeanDeployment.createBeans(BeanDeployment.java:171)
[weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
      at
org.jboss.weld.bootstrap.WeldBootstrap.deployBeans(WeldBootstrap.java:336)
[weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
      at org.jboss.as.weld.WeldContainer.start(WeldContainer.java:82) [jboss-as-weld-7.1.0.Final.jar:7.1.0.Final]
      at
org.jboss.as.weld.services.WeldService.start(WeldService.java:76)
[jboss-as-weld-7.1.0.Final.jar:7.1.0.Final]
      at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)
      at
org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)
      at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [rt.jar:1.6.0_24]
      at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
[rt.jar:1.6.0_24]
      at java.lang.Thread.run(Thread.java:662) [rt.jar:1.6.0_24]
Caused by: java.lang.NoClassDefFoundError:
Lcom/filenet/api/constants/Cardinality;
      at java.lang.Class.getDeclaredFields0(Native Method) [rt.jar:1.6.0_24]
      at
java.lang.Class.privateGetDeclaredFields(Class.java:2291)
[rt.jar:1.6.0_24]
      at java.lang.Class.getDeclaredFields(Class.java:1743) [rt.jar:1.6.0_24]
      at
org.jboss.weld.util.reflection.SecureReflections$4.work(SecureReflections.java:102) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
      at
org.jboss.weld.util.reflection.SecureReflections$4.work(SecureReflections.java:99) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
      at
org.jboss.weld.util.reflection.SecureReflectionAccess.run(SecureReflectionAccess.java:52) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
      at org.jboss.weld.util.reflection.SecureReflectionAccess.runAndWrap(SecureReflectionAccess.java:63) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
      at
org.jboss.weld.util.reflection.SecureReflections.getDeclaredFields(SecureReflections.java:99) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
      at
org.jboss.weld.introspector.jlr.WeldClassImpl.<init>(WeldClassImpl.java:153) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
      at
org.jboss.weld.introspector.jlr.WeldClassImpl.of(WeldClassImpl.java:118)
[weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
      at
org.jboss.weld.resources.ClassTransformer$TransformTypeToWeldClass.apply(ClassTransformer.java:49) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
      at
org.jboss.weld.resources.ClassTransformer$TransformTypeToWeldClass.apply(ClassTransformer.java:40) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
      at
com.google.common.collect.ComputingConcurrentHashMap$ComputingValueReference.compute(ComputingConcurrentHashMap.java:355) [guava-11.0.2.jar:]
      at
com.google.common.collect.ComputingConcurrentHashMap$ComputingSegment.compute(ComputingConcurrentHashMap.java:184) [guava-11.0.2.jar:]
      at
com.google.common.collect.ComputingConcurrentHashMap$ComputingSegment.getOrCompute(ComputingConcurrentHashMap.java:153) [guava-11.0.2.jar:]
      at
com.google.common.collect.ComputingConcurrentHashMap.getOrCompute(ComputingConcurrentHashMap.java:69) [guava-11.0.2.jar:]
      at com.google.common.collect.ComputingConcurrentHashMap$ComputingMapAdapter.get(ComputingConcurrentHashMap.java:393) [guava-11.0.2.jar:]
      at
org.jboss.weld.resources.ClassTransformer.loadClass(ClassTransformer.java:149)
[weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
      ... 11 more
Caused by: java.lang.ClassNotFoundException: com.filenet.api.constants.Cardinality from [Module
"deployment.test-cdi-web.war:main" from Service Module Loader]
      at
org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190)
      at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468)
      at
org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456)
      at
org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:423)
      at
org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)
      at
org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120)
      ... 29 more

Error with Websphere 8.0.x :
6/01/13 16:45:09:504 CET] 0000000e InjectionProc W   CWNEN0047W: Les annotations de ressource pour les champs de la classe com.natixis.sphinx.jsf.filenet.ged.SessionMetadata$PropertyMetadata seront ignorées. Ces annotations n'ont pas pu être obtenues en raison de l'exception suivante : java.lang.NoClassDefFoundError: com.filenet.api.constants.Cardinality
at java.lang.Class.getDeclaredFieldsImpl(Native Method)
at java.lang.Class.getDeclaredFields(Class.java:546)
at com.ibm.wsspi.injectionengine.InjectionProcessor.getAllDeclaredFields(InjectionProcessor.java:569)
at com.ibm.wsspi.injectionengine.InjectionProcessor.processAllAnnotations(InjectionProcessor.java:741)
at com.ibm.ws.injectionengine.AbstractInjectionEngine.processAnnotations(AbstractInjectionEngine.java:684)
at com.ibm.ws.injectionengine.AbstractInjectionEngine.processInjectionMetaData(AbstractInjectionEngine.java:457)
at com.ibm.ws.injectionengine.AbstractInjectionEngine.processInjectionMetaData(AbstractInjectionEngine.java:380)
at com.ibm.ws.webbeans.services.ResourceInjectionServiceImpl.initialize(ResourceInjectionServiceImpl.java:103)
at com.ibm.ws.webbeans.services.JCDIComponentImpl.deployedObjectStart(JCDIComponentImpl.java:327)
at com.ibm.ws.webbeans.services.JCDIComponentImpl.stateChanged(JCDIComponentImpl.java:389)
at com.ibm.ws.runtime.component.ApplicationMgrImpl.stateChanged(ApplicationMgrImpl.java:1105)
at com.ibm.ws.runtime.component.DeployedApplicationImpl.fireDeployedObjectEvent(DeployedApplicationImpl.java:1352)
at com.ibm.ws.runtime.component.DeployedModuleImpl.setState(DeployedModuleImpl.java:247)
at com.ibm.ws.runtime.component.DeployedModuleImpl.start(DeployedModuleImpl.java:635)
at com.ibm.ws.runtime.component.DeployedApplicationImpl.start(DeployedApplicationImpl.java:967)
at com.ibm.ws.runtime.component.ApplicationMgrImpl.startApplication(ApplicationMgrImpl.java:766)
at com.ibm.ws.runtime.component.ApplicationMgrImpl.start(ApplicationMgrImpl.java:2153)
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$CUInitializer.run(CompositionUnitMgrImpl.java:994)
at com.ibm.wsspi.runtime.component.WsComponentImpl$_AsynchInitializer.run(WsComponentImpl.java:349)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1659)
Caused by: java.lang.ClassNotFoundException: com.filenet.api.constants.Cardinality
at java.net.URLClassLoader.findClass(URLClassLoader.java:434)
at com.ibm.ws.bootstrap.ExtClassLoader.findClass(ExtClassLoader.java:198)
at java.lang.ClassLoader.loadClassHelper(ClassLoader.java:665)
at java.lang.ClassLoader.loadClass(ClassLoader.java:644)
at com.ibm.ws.bootstrap.ExtClassLoader.loadClass(ExtClassLoader.java:113)
at java.lang.ClassLoader.loadClass(ClassLoader.java:627)
at com.ibm.ws.classloader.ProtectionClassLoader.loadClass(ProtectionClassLoader.java:62)
at com.ibm.ws.classloader.ProtectionClassLoader.loadClass(ProtectionClassLoader.java:58)
at com.ibm.ws.classloader.CompoundClassLoader.loadClass(CompoundClassLoader.java:565)
at java.lang.ClassLoader.loadClass(ClassLoader.java:627)
at com.ibm.ws.classloader.CompoundClassLoader.loadClass(CompoundClassLoader.java:565)
at java.lang.ClassLoader.loadClass(ClassLoader.java:627)
... 24 more



More information about the cdi-dev mailing list