Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CDI Weld ignoring exclusions

Tags:

java

maven

cdi

weld

I am using Weld SE to use CDI in my application. Since some libraries may have @Inject annotations and and don't want to let Weld scan all the libraries. Therefore I wanted to exclude certain package prefixes in beans.xml:

<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"
version="1.1" bean-discovery-mode="all">
    <scan>
        <exclude name="com.**" />
        <exclude name="org.**" />
        <exclude name="io.**" />
        <exclude name="groovy.**" />
    </scan>
</beans>

but while executing I get the following error:

2014-05-26T17:02:49.855 - INFO  - Version                        - WELD-000900: SNAPSHOT
2014-05-26T17:02:50.340 - WARN  - Bootstrap                      - WELD-001208: Error when validating jar:file:/home/trichner/uepaa/uepaa-net/cloud/target/unet-cloud-0.1-SNAPSHOT-jar-with-dependencies.jar!/META-INF/jboss-beans.xml@19 against xsd. cvc-elt.1: Cannot find the declaration of element 'deployment'.
2014-05-26T17:02:50.408 - INFO  - Bootstrap                      - WELD-000101: Transactional services not available. Injection of @Inject UserTransaction not available. Transactional observers will be invoked synchronously.
2014-05-26T17:02:50.477 - WARN  - Interceptor                    - WELD-001700: Interceptor annotation class javax.ejb.PostActivate not found, interception based on it is not enabled
2014-05-26T17:02:50.477 - WARN  - Interceptor                    - WELD-001700: Interceptor annotation class javax.ejb.PrePassivate not found, interception based on it is not enabled
2014-05-26T17:02:51.425 - INFO  - Bootstrap                      - WELD-000119: Not generating any bean definitions from com.amazonaws.services.simpleworkflow.flow.junit.WorkflowTestStatement because of underlying class loading error: Type org.junit.runners.model.Statement not found.  If this is unexpected, enable DEBUG logging to see the full error.
2014-05-26T17:02:51.425 - INFO  - Bootstrap                      - WELD-000119: Not generating any bean definitions from com.amazonaws.services.simpleworkflow.flow.junit.WorkflowTestBase$3 because of underlying class loading error: Type org.junit.rules.MethodRule not found.  If this is unexpected, enable DEBUG logging to see the full error.
2014-05-26T17:02:51.456 - INFO  - Bootstrap                      - WELD-000119: Not generating any bean definitions from com.amazonaws.services.simpleworkflow.flow.junit.FlowBlockJUnit4ClassRunner because of underlying class loading error: Type org.junit.runners.BlockJUnit4ClassRunner not found.  If this is unexpected, enable DEBUG logging to see the full error.

2014-05-26T17:02:58.061 - INFO  - Bootstrap                      - WELD-000119: Not generating any bean definitions from com.google.common.collect.Multimaps$MapMultimap$AsMap because of underlying class loading error: Type [unknown] not found.  If this is unexpected, enable DEBUG logging to see the full error.
Exception in thread "main" org.jboss.weld.exceptions.DeploymentException: java.lang.InternalError: Enclosing method not found
    at org.jboss.weld.executor.AbstractExecutorServices.checkForExceptions(AbstractExecutorServices.java:66)
    at org.jboss.weld.executor.AbstractExecutorServices.invokeAllAndCheckForExceptions(AbstractExecutorServices.java:43)
    at org.jboss.weld.executor.AbstractExecutorServices.invokeAllAndCheckForExceptions(AbstractExecutorServices.java:51)
        at org.jboss.weld.bootstrap.ConcurrentBeanDeployer.addClasses(ConcurrentBeanDeployer.java:62)
        at org.jboss.weld.bootstrap.BeanDeployment.createClasses(BeanDeployment.java:209)
        at org.jboss.weld.bootstrap.WeldStartup.startInitialization(WeldStartup.java:351)
        at org.jboss.weld.bootstrap.WeldBootstrap.startInitialization(WeldBootstrap.java:76)
        at org.jboss.weld.environment.se.Weld.initialize(Weld.java:133)
        at ch.uepaa.net.cloud.Main.main(Main.java:31)
    Caused by: com.google.common.util.concurrent.ExecutionError: java.lang.InternalError: Enclosing method not found
        at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2199)
        at com.google.common.cache.LocalCache.get(LocalCache.java:3934)
        at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:3938)
        at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4821)
        at org.jboss.weld.util.cache.LoadingCacheUtils.getCacheValue(LoadingCacheUtils.java:52)
        at org.jboss.weld.util.cache.LoadingCacheUtils.getCastCacheValue(LoadingCacheUtils.java:80)
        at org.jboss.weld.resources.ClassTransformer.getBackedAnnotatedType(ClassTransformer.java:175)
        at org.jboss.weld.resources.ClassTransformer.getBackedAnnotatedType(ClassTransformer.java:194)
        at org.jboss.weld.bootstrap.AnnotatedTypeLoader.loadAnnotatedType(AnnotatedTypeLoader.java:78)
        at org.jboss.weld.bootstrap.AnnotatedTypeLoader.loadAnnotatedType(AnnotatedTypeLoader.java:60)
        at org.jboss.weld.bootstrap.BeanDeployer.addClass(BeanDeployer.java:97)
        at org.jboss.weld.bootstrap.ConcurrentBeanDeployer$1.doWork(ConcurrentBeanDeployer.java:65)
        at org.jboss.weld.bootstrap.ConcurrentBeanDeployer$1.doWork(ConcurrentBeanDeployer.java:62)
        at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:60)
        at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:53)
        at java.util.concurrent.FutureTask.run(FutureTask.java:262)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:744)
    Caused by: java.lang.InternalError: Enclosing method not found
        at java.lang.Class.getEnclosingMethod(Class.java:952)
        at sun.reflect.generics.scope.ClassScope.computeEnclosingScope(ClassScope.java:50)
        at sun.reflect.generics.scope.AbstractScope.getEnclosingScope(AbstractScope.java:74)
        at sun.reflect.generics.scope.AbstractScope.lookup(AbstractScope.java:90)
        at sun.reflect.generics.scope.AbstractScope.lookup(AbstractScope.java:90)
        at sun.reflect.generics.factory.CoreReflectionFactory.findTypeVariable(CoreReflectionFactory.java:110)
        at sun.reflect.generics.visitor.Reifier.visitTypeVariableSignature(Reifier.java:165)
        at sun.reflect.generics.tree.TypeVariableSignature.accept(TypeVariableSignature.java:43)
        at sun.reflect.generics.visitor.Reifier.reifyTypeArguments(Reifier.java:68)
        at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:138)
        at sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:49)
        at sun.reflect.generics.repository.MethodRepository.getReturnType(MethodRepository.java:68)
        at java.lang.reflect.Method.getGenericReturnType(Method.java:245)
        at org.jboss.weld.annotated.slim.backed.BackedAnnotatedMethod.<init>(BackedAnnotatedMethod.java:38)
        at org.jboss.weld.annotated.slim.backed.BackedAnnotatedMethod.of(BackedAnnotatedMethod.java:32)
        at org.jboss.weld.annotated.slim.backed.BackedAnnotatedType$BackedAnnotatedMethods.computeValue(BackedAnnotatedType.java:193)
        at org.jboss.weld.annotated.slim.backed.BackedAnnotatedType$BackedAnnotatedMethods.computeValue(BackedAnnotatedType.java:186)
        at org.jboss.weld.util.LazyValueHolder.get(LazyValueHolder.java:35)
        at org.jboss.weld.annotated.slim.backed.BackedAnnotatedType$EagerlyInitializedLazyValueHolder.<init>(BackedAnnotatedType.java:154)
        at org.jboss.weld.annotated.slim.backed.BackedAnnotatedType$BackedAnnotatedMethods.<init>(BackedAnnotatedType.java:186)
        at org.jboss.weld.annotated.slim.backed.BackedAnnotatedType$BackedAnnotatedMethods.<init>(BackedAnnotatedType.java:186)
        at org.jboss.weld.annotated.slim.backed.BackedAnnotatedType.<init>(BackedAnnotatedType.java:66)
        at org.jboss.weld.annotated.slim.backed.BackedAnnotatedType.of(BackedAnnotatedType.java:47)
        at org.jboss.weld.resources.ClassTransformer$TransformClassToBackedAnnotatedType.load(ClassTransformer.java:83)
        at org.jboss.weld.resources.ClassTransformer$TransformClassToBackedAnnotatedType.load(ClassTransformer.java:80)
        at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3524)
        at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2317)
        at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2280)
        at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2195)
        ... 18 more

I'am using following weld version:

    <dependency>
        <groupId>org.jboss.weld.se</groupId>
        <artifactId>weld-se</artifactId>
        <version>2.2.1.Final</version>
    </dependency>

How do I prevent Weld from trying to scan those classes, what exactly fails here?

I checked the format of my beans.xml at least ten times, it should be correct. I want to exclude all those package prefixes. The project is a maven project with all dependencies in the jar (org.** should prevent weld from scanning itself).

like image 368
trichner Avatar asked May 26 '14 15:05

trichner


1 Answers

it may be due to not cleaned up classes from an old deploy/compile cycle, e.g. a missing mvn clean or old class file removal: https://vaadin.com/forum#!/thread/10600799/10604748

like image 98
Andreas Covidiot Avatar answered Nov 14 '22 04:11

Andreas Covidiot