EJB injection impossible in a war application deployed on wildfly via cargo maven plugin

646 views Asked by At

I deploy a war application using cargo maven plugin (wildfly 10 app server) and this happens successfully! But i can't injecting an ejb in a class. This is the console when i exec cargo:run(see the null instance in tail of log..)

[INFO] --- cargo-maven2-plugin:1.5.0:run (default-cli) @ dwrexmio ---
[INFO] [en2.ContainerRunMojo] Resolved container artifact org.codehaus.cargo:cargo-core-container-wildfly:jar:1.5.0 for container wildfly10x
[INFO] [talledLocalContainer] Parsed JBoss version = [10.x]
[INFO] [talledLocalContainer] WildFly 10.x starting...
[INFO] [neLocalConfiguration] Configuring JBoss using the [standalone] server configuration
[INFO] [stalledLocalDeployer] Deploying [C:\Progetti\altri\Dwr-ex-mio\dwrexmio\target\dwrexmio.war] to [C:\Progetti\altri\Dwr-ex-mio\dwrexmio\target\cargo\configurations\wildfly10x/deployments]...
[INFO] [talledLocalContainer] Listening for transport dt_socket at address: 9000
[INFO] [talledLocalContainer] 11:32:06,010 INFO  [org.jboss.modules] (main) JBoss Modules version 1.5.2.Final
[INFO] [talledLocalContainer] 11:32:06,511 INFO  [org.jboss.msc] (main) JBoss MSC version 1.2.6.Final
[INFO] [talledLocalContainer] 11:32:06,596 INFO  [org.jboss.as] (MSC service thread 1-6) WFLYSRV0049: WildFly Full 10.1.0.Final (WildFly Core 2.2.0.Final) starting
...
[INFO] [talledLocalContainer] 11:32:09,462 INFO  [org.jboss.as.ejb3] (MSC service thread 1-5) WFLYEJB0481: Strict pool slsb-strict-max-pool is using a max instance size of 64 (per class), which is derived from thread worker pool sizing.
[INFO] [talledLocalContainer] 11:32:09,468 INFO  [org.jboss.as.ejb3] (MSC service thread 1-6) WFLYEJB0482: Strict pool mdb-strict-max-pool is using a max instance size of 16 (per class), which is derived from the number of CPUs on this host.
[INFO] [talledLocalContainer] 11:32:09,555 INFO  [org.wildfly.extension.undertow] (ServerService Thread Pool -- 55) WFLYUT0014: Creating file handler for path 'C:\Progetti\altri\Dwr-ex-mio\dwrexmio\target\cargo\installs\wildfly-10.1.0.Final\wildfly-10.1.0.Final/welcome-content' with options [directory-listing: 'false', follow-symlink: 'false', case-sensitive: 'true', safe-symlink-paths: '[]']
[INFO] [talledLocalContainer] 11:32:09,773 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-8) WFLYUT0012: Started server default-server.
[INFO] [talledLocalContainer] 11:32:09,774 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-5) WFLYUT0018: Host default-host starting
[INFO] [talledLocalContainer] 11:32:10,099 WARN  [org.jboss.as.domain.management.security] (MSC service thread 1-5) WFLYDM0111: Keystore C:\Progetti\altri\Dwr-ex-mio\dwrexmio\target\cargo\configurations\wildfly10x\configuration\application.keystore not found, it will be auto generated on first use with a self signed certificate for host localhost
[INFO] [talledLocalContainer] 11:32:10,126 INFO  [org.jboss.as.server.deployment.scanner] (MSC service thread 1-3) WFLYDS0013: Started FileSystemDeploymentService for directory C:\Progetti\altri\Dwr-ex-mio\dwrexmio\target\cargo\configurations\wildfly10x\deployments
[INFO] [talledLocalContainer] 11:32:10,134 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-8) WFLYSRV0027: Starting deployment of "cargocpc.war" (runtime-name: "cargocpc.war")
[INFO] [talledLocalContainer] 11:32:10,150 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-5) WFLYSRV0027: Starting deployment of "dwrexmio.war" (runtime-name: "dwrexmio.war")
[INFO] [talledLocalContainer] 11:32:10,642 INFO  [org.infinispan.factories.GlobalComponentRegistry] (MSC service thread 1-8) ISPN000128: Infinispan version: Infinispan 'Chakra' 8.2.4.Final
[INFO] [talledLocalContainer] 11:32:10,758 INFO  [org.infinispan.configuration.cache.EvictionConfigurationBuilder] (ServerService Thread Pool -- 63) ISPN000152: Passivation configured without an eviction policy being selected. Only manually evicted entities will be passivated.
[INFO] [talledLocalContainer] 11:32:10,760 INFO  [org.infinispan.configuration.cache.EvictionConfigurationBuilder] (ServerService Thread Pool -- 63) ISPN000152: Passivation configured without an eviction policy being selected. Only manually evicted entities will be passivated.
[INFO] [talledLocalContainer] 11:32:10,764 INFO  [org.infinispan.configuration.cache.EvictionConfigurationBuilder] (ServerService Thread Pool -- 62) ISPN000152: Passivation configured without an eviction policy being selected. Only manually evicted entities will be passivated.
[INFO] [talledLocalContainer] 11:32:10,765 INFO  [org.infinispan.configuration.cache.EvictionConfigurationBuilder] (ServerService Thread Pool -- 62) ISPN000152: Passivation configured without an eviction policy being selected. Only manually evicted entities will be passivated.
[INFO] [talledLocalContainer] 11:32:10,765 INFO  [org.infinispan.configuration.cache.EvictionConfigurationBuilder] (ServerService Thread Pool -- 60) ISPN000152: Passivation configured without an eviction policy being selected. Only manually evicted entities will be passivated.
[INFO] [talledLocalContainer] 11:32:10,773 INFO  [org.infinispan.configuration.cache.EvictionConfigurationBuilder] (ServerService Thread Pool -- 60) ISPN000152: Passivation configured without an eviction policy being selected. Only manually evicted entities will be passivated.
[INFO] [talledLocalContainer] 11:32:10,781 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-3) WFLYUT0006: Undertow HTTP listener default listening on [0:0:0:0:0:0:0:0]:9090
[INFO] [talledLocalContainer] 11:32:10,883 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-7) WFLYUT0006: Undertow HTTPS listener https listening on [0:0:0:0:0:0:0:0]:8443
[INFO] [talledLocalContainer] 11:32:11,183 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-5) WFLYJCA0001: Bound data source [java:jboss/datasources/ExampleDS]
[INFO] [talledLocalContainer] 11:32:11,246 INFO  [org.jboss.ws.common.management] (MSC service thread 1-7) JBWS022052: Starting JBossWS 5.1.5.Final (Apache CXF 3.1.6) 
[INFO] [talledLocalContainer] 11:32:12,275 INFO  [org.jboss.weld.deployer] (MSC service thread 1-6) WFLYWELD0003: Processing weld deployment dwrexmio.war
[INFO] [talledLocalContainer] 11:32:12,324 INFO  [org.wildfly.extension.undertow] (ServerService Thread Pool -- 59) WFLYUT0021: Registered web context: /cargocpc
[INFO] [talledLocalContainer] 11:32:12,384 INFO  [org.hibernate.validator.internal.util.Version] (MSC service thread 1-6) HV000001: Hibernate Validator 5.2.4.Final
[INFO] [talledLocalContainer] WildFly 10.x started on port [9090]
[INFO] Press Ctrl-C to stop the container...
[INFO] [talledLocalContainer] 11:32:12,484 INFO  [org.jboss.as.ejb3.deployment] (MSC service thread 1-6) WFLYEJB0473: JNDI bindings for session bean named 'TimerEjb2' in deployment unit 'deployment "dwrexmio.war"' are as follows:
[INFO] [talledLocalContainer] 
[INFO] [talledLocalContainer]   java:global/dwrexmio/TimerEjb2!com.cadit.bean.TimerEjb2
[INFO] [talledLocalContainer]   java:app/dwrexmio/TimerEjb2!com.cadit.bean.TimerEjb2
[INFO] [talledLocalContainer]   java:module/TimerEjb2!com.cadit.bean.TimerEjb2
[INFO] [talledLocalContainer]   java:global/dwrexmio/TimerEjb2
[INFO] [talledLocalContainer]   java:app/dwrexmio/TimerEjb2
[INFO] [talledLocalContainer]   java:module/TimerEjb2
[INFO] [talledLocalContainer] 
[INFO] [talledLocalContainer] 11:32:12,675 INFO  [org.infinispan.configuration.cache.EvictionConfigurationBuilder] (ServerService Thread Pool -- 59) ISPN000152: Passivation configured without an eviction policy being selected. Only manually evicted entities will be passivated.
[INFO] [talledLocalContainer] 11:32:12,680 INFO  [org.infinispan.configuration.cache.EvictionConfigurationBuilder] (ServerService Thread Pool -- 59) ISPN000152: Passivation configured without an eviction policy being selected. Only manually evicted entities will be passivated.
[INFO] [talledLocalContainer] 11:32:12,791 INFO  [org.jboss.weld.Version] (MSC service thread 1-6) WELD-000900: 2.3.5 (Final)
[INFO] [talledLocalContainer] 11:32:13,205 INFO  [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 59) WFLYCLINF0002: Started client-mappings cache from ejb container
[INFO] [talledLocalContainer] 11:32:13,978 INFO  [javax.enterprise.resource.webcontainer.jsf.config] (ServerService Thread Pool -- 60) Initializing Mojarra 2.2.13.SP1 20160303-1204 for context '/dwrexmio'
[INFO] [talledLocalContainer] 11:32:14,751 INFO  [org.directwebremoting.log.startup] (ServerService Thread Pool -- 60) Starting: DwrServlet v3.0.3-dev on WildFly 2.2.0.Final - 1.4.0.Final / JDK 1.8.0_65 from Oracle Corporation at /dwrexmio
[INFO] [talledLocalContainer] 11:32:14,797 INFO  [org.directwebremoting.log.startup] (ServerService Thread Pool -- 60) Starting: Using container abstraction org.directwebremoting.server.servlet2.Servlet24ContainerAbstraction
[INFO] [talledLocalContainer] 11:32:14,913 INFO  [org.wildfly.extension.undertow] (ServerService Thread Pool -- 60) WFLYUT0021: Registered web context: /dwrexmio
[INFO] [talledLocalContainer] 11:32:14,951 INFO  [org.jboss.as.server] (ServerService Thread Pool -- 34) WFLYSRV0010: Deployed "dwrexmio.war" (runtime-name : "dwrexmio.war")
[INFO] [talledLocalContainer] 11:32:14,951 INFO  [org.jboss.as.server] (ServerService Thread Pool -- 34) WFLYSRV0010: Deployed "cargocpc.war" (runtime-name : "cargocpc.war")
[INFO] [talledLocalContainer] 11:32:15,111 INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0060: Http management interface listening on http://127.0.0.1:9050/management
[INFO] [talledLocalContainer] 11:32:15,111 INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0051: Admin console listening on http://127.0.0.1:9050
[INFO] [talledLocalContainer] 11:32:15,112 INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0025: WildFly Full 10.1.0.Final (WildFly Core 2.2.0.Final) started in 9478ms - Started 536 of 778 services (415 services are lazy, passive or on-demand)
[INFO] [talledLocalContainer] 11:33:02,043 INFO  [stdout] (default task-45) null

My ejb is Timer2EJB:

import javax.annotation.Resource;
import javax.ejb.Stateless;
import javax.enterprise.concurrent.ManagedScheduledExecutorService;


    @Stateless
    public class TimerEjb2 {


        @Resource//(lookup="java:jboss/ee/concurrency/scheduler/default")
        private ManagedScheduledExecutorService executorService; 


        public TimerEjb2() {

        }

        public void startTask(PushEndPoint pushEndpoint){
            executorService.scheduleAtFixedRate(pushEndpoint, 1, 50, TimeUnit.MILLISECONDS);
        }

        public void shutdownTask(){
            executorService.shutdown();
            try {
                executorService.awaitTermination(3000, TimeUnit.SECONDS);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

    }

pushEndpoint implements Runnable. But when i execute this class the injection not happens:

import javax.ejb.EJB;

public class Testejb {

    @EJB
       TimerEjb2 timerEjb2;

    public void test(){
        System.out.println(timerEjb2); <--this is null in log!
    }
}

the same things if i add (lookup="java:global/dwrexmio/TimerEjb2!com.cadit.bean.TimerEjb2") before @EJB

In webapp\WEB-INF there is web.xml and the beans.xml and ejb-jar.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"
    bean-discovery-mode="all">
</beans>

<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
         version="3.1"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd">

</ejb-jar>

This is my pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.cadit</groupId>
  <artifactId>dwrexmio</artifactId>
  <packaging>war</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>dwrexmio Maven Webapp</name>
  <url>http://maven.apache.org</url>
    <build>
        <finalName>dwrexmio</finalName>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <webResources>
                        <resource>
                            <directory>src/main/webapp/WEB-INF</directory>
                            <targetPath>WEB-INF</targetPath>
                            <includes>
                                <include>*.xml</include>
                            </includes>
                            <filtering>true</filtering>
                        </resource>
                    </webResources>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.cargo</groupId>
                <artifactId>cargo-maven2-plugin</artifactId>
                <version>1.5.0</version>
                <configuration>
                    <container>
                        <containerId>wildfly10x</containerId>
                        <zipUrlInstaller>
                                <url>
                                    http://download.jboss.org/wildfly/10.1.0.Final/wildfly-10.1.0.Final.zip
                                </url>
                        </zipUrlInstaller>
                    </container>
                    <configuration>
                        <files>
                            <copy>
                                <file>${project.basedir}/src/main/jboss/configuration/</file>
                                <todir>
                                    ../../installs/wildfly-10.1.0.Final/wildfly-10.1.0.Final/standalone/configuration
                                </todir>
                                <configfile>true</configfile>
                                <overwrite>true</overwrite>
                            </copy>
                            <copy>
                                <file>${project.basedir}/src/main/jboss/configuration/</file>
                                <todir>../../configurations/wildfly10x/configuration</todir>
                                <configfile>true</configfile>
                                <overwrite>true</overwrite>
                            </copy>
                        </files>
                        <properties>
                            <cargo.start.jvmargs>
                                -Xdebug
                                -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=9000
                                -Xnoagent
                                -Djava.compiler=NONE
                            </cargo.start.jvmargs>
                            <cargo.jboss.modules.dir>modules</cargo.jboss.modules.dir>
                            <cargo.servlet.port>9090</cargo.servlet.port>
                            <cargo.jboss.management-http.port>9050</cargo.jboss.management-http.port>
                            <cargo.servlet.users>admin:admin</cargo.servlet.users>
                        </properties>
                    </configuration>
                </configuration>
            </plugin>
        </plugins>
    </build>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.2</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.directwebremoting</groupId>
            <artifactId>dwr</artifactId>
            <version>3.0.2-RELEASE</version>
        </dependency>
            <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.2</version>
            <scope>runtime</scope>
        </dependency>
         <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>7.0</version>
            <scope>provided</scope>
        </dependency>
          <dependency>
            <groupId>javax.enterprise</groupId>
            <artifactId>cdi-api</artifactId>
            <version>1.2</version>
            <scope>provided</scope>
        </dependency>



  </dependencies>

</project>

what's wrong?

Thank you very much!

Roby

2

There are 2 answers

0
James R. Perkins On

You're Testejb is not managed by the container and therefore the EJB cannot be injected. You need to run your test with something like Arquillian that can run tests in the container.

0
Georg Leber On

Add @Stateless to your Testejb otherwise it is not managed by the application server and dependencies are not injected.