0

我试图在一个非常简单的示例中使weld-se 工作,该示例基本上遵循这个。但是,我无法让它工作。

我使用 gradle 进行构建。这是我的 build.gradle:

apply plugin: 'java'

version='1.0-SNAPSHOT'

repositories {
    mavenCentral()
}

task wrapper(type: Wrapper) {
    gradleVersion = '1.8'
}

jar {
    dependsOn configurations.runtime
    from { configurations.runtime.collect { it.isDirectory() ? it : zipTree(it) } }
}

task hello( type: JavaExec) {
    main = 'org.jboss.weld.environment.se.StartMain'
    classpath = sourceSets.main.runtimeClasspath
}

dependencies {
    compile 'org.jboss.weld.se:weld-se:2.0.4.Final'
}

我在 src 文件夹中有这些文件。

./src/main/java/weldse/HelloWorld.java
./src/main/resources/META-INF/beans.xml

内容如下。

HelloWorld.java

package weldse;

import org.jboss.weld.environment.se.events.ContainerInitialized;

import javax.enterprise.event.Observes;

public class HelloWorld {

    public void printHello( @Observes ContainerInitialized event) {
        System.out.println("Hello, World");
    }
}

豆类.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">
</beans>

当我运行时gradle hello,我没有得到输出Hello, World,而是BUILD SUCCESSFUL带有以下消息:

[main] INFO org.jboss.weld.Version - WELD-000900 2.0.4 (Final)
[main] INFO org.jboss.weld.Bootstrap - WELD-000101 Transactional services not available. Injection of @Inject UserTransaction not available. Transactional observers will be invoked synchronously.
[main] WARN org.jboss.weld.interceptor.util.InterceptionTypeRegistry - Class 'javax.ejb.PostActivate' not found, interception based on it is not enabled
[main] WARN org.jboss.weld.interceptor.util.InterceptionTypeRegistry - Class 'javax.ejb.PrePassivate' not found, interception based on it is not enabled

但是,当我直接使用 运行它时java,会出现异常。这是完整的堆栈跟踪。

$ java -cp build/libs/weld-se-1.0-SNAPSHOT.jar org.jboss.weld.environment.se.StartMain
[main] INFO org.jboss.weld.Version - WELD-000900 SNAPSHOT
[main] INFO org.jboss.weld.Bootstrap - WELD-000101 Transactional services not available. Injection of @Inject UserTransaction not available. Transactional observers will be invoked synchronously.
[weld-worker-5] INFO org.jboss.weld.ClassLoading - WELD-000119 Not generating any bean definitions from org.jboss.weld.bean.builtin.ee.HttpSessionBean because of underlying class loading error: Type javax.servlet.http.HttpSession not found.  If this is unexpected, enable DEBUG logging to see the full error.
[weld-worker-3] INFO org.jboss.weld.ClassLoading - WELD-000119 Not generating any bean definitions from org.jboss.weld.bean.builtin.ee.HttpServletRequestBean because of underlying class loading error: Type javax.servlet.http.HttpServletRequest not found.  If this is unexpected, enable DEBUG logging to see the full error.
[weld-worker-2] INFO org.jboss.weld.ClassLoading - WELD-000119 Not generating any bean definitions from org.jboss.weld.bean.builtin.ee.ServletContextBean because of underlying class loading error: Type javax.servlet.ServletContext not found.  If this is unexpected, enable DEBUG logging to see the full error.
[weld-worker-4] INFO org.jboss.weld.ClassLoading - WELD-000119 Not generating any bean definitions from org.jboss.weld.bean.builtin.ee.UserTransactionBean$UserTransactionCallable because of underlying class loading error: Type javax.transaction.UserTransaction not found.  If this is unexpected, enable DEBUG logging to see the full error.
[weld-worker-6] INFO org.jboss.weld.ClassLoading - WELD-000119 Not generating any bean definitions from org.jboss.weld.context.beanstore.http.RequestBeanStore because of underlying class loading error: Type javax.servlet.http.HttpServletRequest not found.  If this is unexpected, enable DEBUG logging to see the full error.
[weld-worker-1] INFO org.jboss.weld.ClassLoading - WELD-000119 Not generating any bean definitions from org.jboss.weld.context.beanstore.http.LazySessionBeanStore because of underlying class loading error: Type javax.servlet.http.HttpServletRequest not found.  If this is unexpected, enable DEBUG logging to see the full error.
[weld-worker-8] INFO org.jboss.weld.ClassLoading - WELD-000119 Not generating any bean definitions from org.jboss.weld.context.beanstore.http.EagerSessionBeanStore because of underlying class loading error: Type javax.servlet.http.HttpSession not found.  If this is unexpected, enable DEBUG logging to see the full error.
[weld-worker-7] INFO org.jboss.weld.ClassLoading - WELD-000119 Not generating any bean definitions from org.jboss.weld.context.beanstore.http.AbstractSessionBeanStore because of underlying class loading error: Type javax.servlet.http.HttpSession not found.  If this is unexpected, enable DEBUG logging to see the full error.
[weld-worker-3] INFO org.jboss.weld.ClassLoading - WELD-000119 Not generating any bean definitions from org.jboss.weld.context.beanstore.http.LazyCyclicSessionBeanStore because of underlying class loading error: Type javax.servlet.http.HttpServletRequest not found.  If this is unexpected, enable DEBUG logging to see the full error.
[weld-worker-5] INFO org.jboss.weld.ClassLoading - WELD-000119 Not generating any bean definitions from org.jboss.weld.context.http.HttpConversationContext because of underlying class loading error: Type javax.servlet.http.HttpSession not found.  If this is unexpected, enable DEBUG logging to see the full error.
[weld-worker-8] INFO org.jboss.weld.ClassLoading - WELD-000119 Not generating any bean definitions from org.jboss.weld.context.http.HttpSessionContext because of underlying class loading error: Type javax.servlet.http.HttpSession not found.  If this is unexpected, enable DEBUG logging to see the full error.
[weld-worker-4] INFO org.jboss.weld.ClassLoading - WELD-000119 Not generating any bean definitions from org.jboss.weld.context.http.HttpRequestContextImpl because of underlying class loading error: Type javax.servlet.http.HttpServletRequest not found.  If this is unexpected, enable DEBUG logging to see the full error.
[weld-worker-3] INFO org.jboss.weld.ClassLoading - WELD-000119 Not generating any bean definitions from org.jboss.weld.context.http.HttpConversationContextImpl because of underlying class loading error: Type javax.servlet.http.HttpSession not found.  If this is unexpected, enable DEBUG logging to see the full error.
[weld-worker-5] INFO org.jboss.weld.ClassLoading - WELD-000119 Not generating any bean definitions from org.jboss.weld.context.http.HttpSessionDestructionContext because of underlying class loading error: Type javax.servlet.http.HttpSession not found.  If this is unexpected, enable DEBUG logging to see the full error.
[weld-worker-1] INFO org.jboss.weld.ClassLoading - WELD-000119 Not generating any bean definitions from org.jboss.weld.context.http.HttpSessionContextImpl because of underlying class loading error: Type javax.servlet.http.HttpSession not found.  If this is unexpected, enable DEBUG logging to see the full error.
[weld-worker-8] INFO org.jboss.weld.ClassLoading - WELD-000119 Not generating any bean definitions from org.jboss.weld.event.TransactionalObserverNotifier because of underlying class loading error: Type javax.transaction.Synchronization not found.  If this is unexpected, enable DEBUG logging to see the full error.
[weld-worker-1] INFO org.jboss.weld.ClassLoading - WELD-000119 Not generating any bean definitions from org.jboss.weld.event.TransactionSynchronizedRunnable because of underlying class loading error: Type javax.transaction.Synchronization not found.  If this is unexpected, enable DEBUG logging to see the full error.
[weld-worker-1] INFO org.jboss.weld.ClassLoading - WELD-000119 Not generating any bean definitions from org.jboss.weld.injection.spi.JpaInjectionServices because of underlying class loading error: Type javax.persistence.EntityManager not found.  If this is unexpected, enable DEBUG logging to see the full error.
[weld-worker-1] INFO org.jboss.weld.ClassLoading - WELD-000119 Not generating any bean definitions from org.jboss.weld.injection.spi.helpers.ForwardingJpaInjectionServices because of underlying class loading error: Type javax.persistence.EntityManager not found.  If this is unexpected, enable DEBUG logging to see the full error.
[weld-worker-3] INFO org.jboss.weld.ClassLoading - WELD-000119 Not generating any bean definitions from org.jboss.weld.servlet.SessionHolder because of underlying class loading error: Type javax.servlet.http.HttpSession not found.  If this is unexpected, enable DEBUG logging to see the full error.
[weld-worker-8] INFO org.jboss.weld.ClassLoading - WELD-000119 Not generating any bean definitions from org.jboss.weld.servlet.ConversationFilter because of underlying class loading error: Type javax.servlet.Filter not found.  If this is unexpected, enable DEBUG logging to see the full error.
[weld-worker-3] INFO org.jboss.weld.ClassLoading - WELD-000119 Not generating any bean definitions from org.jboss.weld.servlet.WeldCrossContextFilter because of underlying class loading error: Type javax.servlet.Filter not found.  If this is unexpected, enable DEBUG logging to see the full error.
[weld-worker-2] INFO org.jboss.weld.ClassLoading - WELD-000119 Not generating any bean definitions from org.jboss.weld.servlet.ConversationContextActivator because of underlying class loading error: Type javax.servlet.http.HttpServletRequest not found.  If this is unexpected, enable DEBUG logging to see the full error.
[weld-worker-1] INFO org.jboss.weld.ClassLoading - WELD-000119 Not generating any bean definitions from org.jboss.weld.servlet.WeldTerminalListener because of underlying class loading error: Type javax.servlet.http.HttpSessionListener not found.  If this is unexpected, enable DEBUG logging to see the full error.
[weld-worker-6] INFO org.jboss.weld.ClassLoading - WELD-000119 Not generating any bean definitions from org.jboss.weld.servlet.WeldListener because of underlying class loading error: Type javax.servlet.ServletContextListener not found.  If this is unexpected, enable DEBUG logging to see the full error.
[weld-worker-2] INFO org.jboss.weld.ClassLoading - WELD-000119 Not generating any bean definitions from org.jboss.weld.servlet.api.helpers.ForwardingServletListener because of underlying class loading error: Type javax.servlet.ServletContextListener not found.  If this is unexpected, enable DEBUG logging to see the full error.
[weld-worker-8] INFO org.jboss.weld.ClassLoading - WELD-000119 Not generating any bean definitions from org.jboss.weld.servlet.WeldInitialListener because of underlying class loading error: Type javax.servlet.ServletContextListener not found.  If this is unexpected, enable DEBUG logging to see the full error.
[weld-worker-4] INFO org.jboss.weld.ClassLoading - WELD-000119 Not generating any bean definitions from org.jboss.weld.transaction.spi.TransactionServices because of underlying class loading error: Type javax.transaction.Synchronization not found.  If this is unexpected, enable DEBUG logging to see the full error.
[weld-worker-3] INFO org.jboss.weld.ClassLoading - WELD-000119 Not generating any bean definitions from org.jboss.weld.servlet.api.helpers.AbstractServletListener because of underlying class loading error: Type javax.servlet.ServletContextListener not found.  If this is unexpected, enable DEBUG logging to see the full error.
[weld-worker-5] INFO org.jboss.weld.ClassLoading - WELD-000119 Not generating any bean definitions from org.jboss.weld.servlet.api.ServletListener because of underlying class loading error: Type javax.servlet.ServletContextListener not found.  If this is unexpected, enable DEBUG logging to see the full error.
[weld-worker-7] INFO org.jboss.weld.ClassLoading - WELD-000119 Not generating any bean definitions from org.jboss.weld.servlet.HttpContextLifecycle because of underlying class loading error: Type javax.servlet.http.HttpServletRequest not found.  If this is unexpected, enable DEBUG logging to see the full error.
[weld-worker-4] INFO org.jboss.weld.ClassLoading - WELD-000119 Not generating any bean definitions from org.jboss.weld.validation.spi.ValidationServices because of underlying class loading error: Type javax.validation.ValidatorFactory not found.  If this is unexpected, enable DEBUG logging to see the full error.
[weld-worker-8] INFO org.jboss.weld.ClassLoading - WELD-000119 Not generating any bean definitions from org.slf4j.ext.MDCStrLookup because of underlying class loading error: Type org.apache.commons.lang.text.StrLookup not found.  If this is unexpected, enable DEBUG logging to see the full error.
[weld-worker-6] INFO org.jboss.weld.ClassLoading - WELD-000119 Not generating any bean definitions from org.slf4j.instrumentation.JavassistHelper because of underlying class loading error: Type javassist.CtBehavior not found.  If this is unexpected, enable DEBUG logging to see the full error.
[weld-worker-7] INFO org.jboss.weld.ClassLoading - WELD-000119 Not generating any bean definitions from org.slf4j.instrumentation.LogTransformer because of underlying class loading error: Type javassist.CtBehavior not found.  If this is unexpected, enable DEBUG logging to see the full error.
[main] WARN org.jboss.weld.interceptor.util.InterceptionTypeRegistry - Class 'javax.ejb.PostActivate' not found, interception based on it is not enabled
[main] WARN org.jboss.weld.interceptor.util.InterceptionTypeRegistry - Class 'javax.ejb.PrePassivate' not found, interception based on it is not enabled
Exception in thread "main" org.jboss.weld.exceptions.DeploymentException: Exception List with 4 exceptions:
Exception 0 :
org.jboss.weld.exceptions.DeploymentException: WELD-001409 Ambiguous dependencies for type InstanceManager with qualifiers @Default
  at injection point [UnbackedAnnotatedParameter] Parameter 1 of [UnbackedAnnotatedConstructor] @Inject protected org.jboss.weld.environment.se.WeldContainer(InstanceManager, BeanManager)
  at org.jboss.weld.environment.se.WeldContainer.<init>(WeldContainer.java:0)
  Possible dependencies:
  - Managed Bean [class org.jboss.weld.environment.se.beans.InstanceManager] with qualifiers [@Any @Default],
  - Managed Bean [class org.jboss.weld.environment.se.beans.InstanceManager] with qualifiers [@Any @Default]

    at org.jboss.weld.bootstrap.Validator.validateInjectionPointForDeploymentProblems(Validator.java:412)
    at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:327)
    at org.jboss.weld.bootstrap.Validator.validateGeneralBean(Validator.java:178)
    at org.jboss.weld.bootstrap.Validator.validateRIBean(Validator.java:209)
    at org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:530)
    at org.jboss.weld.bootstrap.ConcurrentValidator$1.doWork(ConcurrentValidator.java:71)
    at org.jboss.weld.bootstrap.ConcurrentValidator$1.doWork(ConcurrentValidator.java:69)
    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$Sync.innerRun(FutureTask.java:334)
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    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:724)
Exception 0 :
org.jboss.weld.exceptions.DeploymentException: WELD-001409 Ambiguous dependencies for type InstanceManager with qualifiers @Default
  at injection point [BackedAnnotatedParameter] Parameter 1 of [BackedAnnotatedConstructor] @Inject protected org.jboss.weld.environment.se.WeldContainer(InstanceManager, BeanManager)
  at org.jboss.weld.environment.se.WeldContainer.<init>(WeldContainer.java:0)
  Possible dependencies:
  - Managed Bean [class org.jboss.weld.environment.se.beans.InstanceManager] with qualifiers [@Any @Default],
  - Managed Bean [class org.jboss.weld.environment.se.beans.InstanceManager] with qualifiers [@Any @Default]

    at org.jboss.weld.bootstrap.Validator.validateInjectionPointForDeploymentProblems(Validator.java:412)
    at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:327)
    at org.jboss.weld.bootstrap.Validator.validateGeneralBean(Validator.java:178)
    at org.jboss.weld.bootstrap.Validator.validateRIBean(Validator.java:209)
    at org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:530)
    at org.jboss.weld.bootstrap.ConcurrentValidator$1.doWork(ConcurrentValidator.java:71)
    at org.jboss.weld.bootstrap.ConcurrentValidator$1.doWork(ConcurrentValidator.java:69)
    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$Sync.innerRun(FutureTask.java:334)
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    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:724)
Exception 0 :
org.jboss.weld.exceptions.DeploymentException: WELD-001409 Ambiguous dependencies for type Instance<Object> with qualifiers @Any
  at injection point [UnbackedAnnotatedField] @Inject @Any org.jboss.weld.environment.se.beans.InstanceManager.instances
  at org.jboss.weld.environment.se.beans.InstanceManager.instances(InstanceManager.java:0)
  Possible dependencies:
  - Managed Bean [class org.jboss.weld.Weld] with qualifiers [@Any @Default],
  - Implicit Bean [javax.enterprise.inject.Instance] with qualifiers [@Default],
  - Managed Bean [class org.jboss.weld.servlet.StaticWeldProvider$EnhancedWeld] with qualifiers [@Any @Default]

    at org.jboss.weld.bootstrap.Validator.validateInjectionPointForDeploymentProblems(Validator.java:412)
    at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:327)
    at org.jboss.weld.bootstrap.Validator.validateGeneralBean(Validator.java:178)
    at org.jboss.weld.bootstrap.Validator.validateRIBean(Validator.java:209)
    at org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:530)
    at org.jboss.weld.bootstrap.ConcurrentValidator$1.doWork(ConcurrentValidator.java:71)
    at org.jboss.weld.bootstrap.ConcurrentValidator$1.doWork(ConcurrentValidator.java:69)
    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$Sync.innerRun(FutureTask.java:334)
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    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:724)
Exception 0 :
org.jboss.weld.exceptions.DeploymentException: WELD-001409 Ambiguous dependencies for type Instance<Object> with qualifiers @Any
  at injection point [BackedAnnotatedField] @Inject @Any org.jboss.weld.environment.se.beans.InstanceManager.instances
  at org.jboss.weld.environment.se.beans.InstanceManager.instances(InstanceManager.java:0)
  Possible dependencies:
  - Managed Bean [class org.jboss.weld.Weld] with qualifiers [@Any @Default],
  - Implicit Bean [javax.enterprise.inject.Instance] with qualifiers [@Default],
  - Managed Bean [class org.jboss.weld.servlet.StaticWeldProvider$EnhancedWeld] with qualifiers [@Any @Default]

    at org.jboss.weld.bootstrap.Validator.validateInjectionPointForDeploymentProblems(Validator.java:412)
    at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:327)
    at org.jboss.weld.bootstrap.Validator.validateGeneralBean(Validator.java:178)
    at org.jboss.weld.bootstrap.Validator.validateRIBean(Validator.java:209)
    at org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:530)
    at org.jboss.weld.bootstrap.ConcurrentValidator$1.doWork(ConcurrentValidator.java:71)
    at org.jboss.weld.bootstrap.ConcurrentValidator$1.doWork(ConcurrentValidator.java:69)
    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$Sync.innerRun(FutureTask.java:334)
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    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:724)

    at org.jboss.weld.bootstrap.ConcurrentValidator.validateBeans(ConcurrentValidator.java:79)
    at org.jboss.weld.bootstrap.Validator.validateDeployment(Validator.java:491)
    at org.jboss.weld.bootstrap.WeldBootstrap.validateBeans(WeldBootstrap.java:538)
    at org.jboss.weld.bootstrap.api.helpers.ForwardingBootstrap.validateBeans(ForwardingBootstrap.java:75)
    at org.jboss.weld.environment.se.Weld.initialize(Weld.java:144)
    at org.jboss.weld.environment.se.StartMain.go(StartMain.java:41)
    at org.jboss.weld.environment.se.StartMain.main(StartMain.java:52)

在我看来,InstanceManager这是导致异常的模棱两可。但是,我不确定。无论如何,您知道如何进行这项工作吗?非常感谢。

4

1 回答 1

4

看来这是weld-se的一个问题,并且不会很快得到解决。无论如何,我找到了一个解决方法,它基本上不包括焊接的 bean 扫描。万一解决方法的链接在将来过期,这里是解决方法 beans.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:weld="http://jboss.org/schema/weld/beans"
    xsi:schemaLocation="
          http://java.sun.com/xml/ns/javaee http://docs.jboss.org/cdi/beans_1_0.xsd
          http://jboss.org/schema/weld/beans http://jboss.org/schema/weld/beans_1_1.xsd">
    <weld:scan>
        <weld:exclude name="org.jboss.weld.**" />
    </weld:scan>
</beans>

基本上,您需要做的就是将它beans.xml与您当前的 beans.xml 合并。

于 2013-10-08T05:28:31.303 回答