javacdiweldjboss-weldweld-se

Weld-SE not starting , no beans archive found


I'm trying to init CDI-SE context inside my Quartz Application, so i have the following dependency (maven):

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

Inside my JobQuartz i have the method execute() with the following:

public void execute(JobExecutionContext context) throws JobExecutionException {
        Weld weld = new Weld();
        WeldContainer container = weld.initialize();
        service = container.instance().select(MyService.class).get();
        service.go();
        weld.shutdown();
    }

But i got the following error:

Caused by: java.lang.IllegalStateException: WELD-ENV-002009: Weld SE container cannot be initialized - no bean archives found

My project is a WAR, so i putted beans.xml file inside /src/main/webapp/META-INF/, see the content:

<?xml version="1.0"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns="http://xmlns.jcp.org/xml/ns/javaee"
       xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
       version="1.2" bean-discovery-mode="all">

</beans>

I copied the file to /src/main/resource/META-INF, but i got the same error.


Solution

  • After some conversation in comments section I think I understand enough to answer you.

    First of all, you should not start Weld SE container on your own as you then have two containers running side by side (which isn't intended/supported) - one SE and one "classic", handled by the container. Stick with the container-handled one, which is booted for you effortlessly.

    Now, I see you are missing some scope activation means. If you are using some newer version of Weld, you can make use of an interceptor, which will activate RequestContext (I suppose that's the one you are after) before a method and tear it down afterwards. All you need for that is a dependency on Weld API (which is included in WFLY anyway) and then you simply annotate your method or class with that.

    For the above you need Weld 2.4.x. Note that you can quite simply patch your WildFly. The patches are at the bottom of the Weld website and the how-to can be found here.

    If you were to use Weld 3/CDI 2.0 then there is even a built-in bean (RequestContextController) which allows you to control this lifecycle.

    Other option is then Deltaspike, as Johm Ament pointed out, but that requires you to bring in another dependency.