Question

I am trying to make weld-se work in a very simple example, which basically follows this one. However, I can't get it work.

I use gradle for building. Here is my 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'
}

I have these files in the src folder.

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

The contents are listed below.

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");
    }
}

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">
</beans>

When I run gradle hello, I don't get the output Hello, World but a BUILD SUCCESSFUL with these messages:

[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

However, when I run it directly with java, I get exceptions. Here is full stacktrace.

$ 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)

It seems to me there is an ambiguity of InstanceManager that is causing the exceptions. However, I don't know for sure. Anyway, do you know how to make this work? Thank you very much.

Was it helpful?

Solution

It appears that this is an issue to weld-se, and is not going to be fixed any time soon. In any case, I found a workaround for it, which basically excludes bean scanning for weld. In case the link to the workaround expires in the future, here is the workaround 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>

Basically, what you need to do is merge this beans.xml with your current beans.xml.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top