我正在使用Weld SE在我的应用程序中使用CDI。由于某些库可能有@Inject注释,并且不想让Weld扫描所有库。因此,我想在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>
但在执行时我收到以下错误:
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
我正在使用以下焊接版本:
<dependency>
<groupId>org.jboss.weld.se</groupId>
<artifactId>weld-se</artifactId>
<version>2.2.1.Final</version>
</dependency>
如何阻止Weld尝试扫描这些类,这里究竟失败了什么?
我检查了beans.xml的格式至少十次,应该是正确的。我想要 排除所有这些包前缀。该项目是一个maven项目,包含jar中的所有依赖项(org。**应该防止焊接扫描本身)。
答案 0 :(得分:5)
可能是因为没有从旧的部署/编译周期中清除类,例如缺少mvn clean
或旧类文件删除:https://vaadin.com/forum#!/thread/10600799/10604748