1 Reply Latest reply on Feb 24, 2017 11:19 AM by Heinz Erhard

    How to use Message-Driven-Bean module together with a war-application sharing the spring application context

    Heinz Erhard Newbie

      Hello,

       

      I have difficulties migrating to JBoss EAP 7.0.0.

       

      Theres a EJB-module containing three message driven beans.

      Theres a war-module containing the web app doing all the stuff.

      Both are packed into an ear-file.

       

      We use spring in both modules for injection etc.

       

       

      In general most things works fine.

      Except for an injection into the MDB.

       

      I think the problem is that the MDB cannot access the application context which was initialized by the war-module.

      Due to existing code and some hits on google I seems to be working on later versions of JBoss.

      Because of the MDB cannot access the application context the desired autowiring does not take place.

       

      Im am now looking for any way to get this working, may by reorganizing or reconfiguring something.

      This I where I request some help.

       

      In the following I will share my codes:

       

      one of those MDBs:

       

      MessageDriven(name = "MyProjectIntern-Bean", activationConfig = {
         @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
         @ActivationConfigProperty(propertyName = "destination", propertyValue = "queue/q_myproject_intern") })
      @Interceptors(SpringBeanAutowiringInterceptor.class)
      public class MyprojectInternMDB extends BaseMDB implements MessageListener {
      
         @Override
         @Autowired
         public void setMessageHandler(@Qualifier("myprojectInternalMessageHandler") MessageHandler messageHandler) {
         this.messageHandler = messageHandler;
         }
      }
      

       

      this is the ears-pom definition:

      <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/xsd/maven-4.0.0.xsd">
          <modelVersion>4.0.0</modelVersion>
      
          <artifactId>ear</artifactId>
          <packaging>ear</packaging>
          <name>MyProject EAR</name>
          <description>MyProject 03.500</description>
      
          <parent>
              <groupId>com.corp.myproject</groupId>
              <artifactId>parent</artifactId>
              <version>3.500.1-SNAPSHOT</version>
              <relativePath>../parent</relativePath>
          </parent>
      
          <build>
              <plugins>
                  <plugin>
                      <artifactId>maven-ear-plugin</artifactId>
                      <version>2.10.1</version>
                      <configuration>
                          <defaultLibBundleDir>lib/</defaultLibBundleDir>
                          <skinnyWars>true</skinnyWars>
      
                          <modules>
                              <webModule>
                                  <groupId>com.corp.myproject</groupId>
                                  <artifactId>web</artifactId>
                                  <context-root>myproject</context-root>
                              </webModule>
                              <jarModule>
                              [...]
                              </jarModule>
                              <ejbModule>
                                  <groupId>com.corp.myproject</groupId>
                                  <artifactId>message-driven-beans</artifactId>
                              </ejbModule>
                          </modules>
                      </configuration>
                  </plugin>
              </plugins>
          </build>
      
          <dependencies>
              <dependency>
                  [...]
              </dependency>
              <dependency>
                  <groupId>com.corp.myproject</groupId>
                  <artifactId>web</artifactId>
                  <version>${project.version}</version>
                  <type>war</type>
              </dependency>
              <dependency>
                  <groupId>com.corp.myproject</groupId>
                  <artifactId>message-driven-beans</artifactId>
                  <version>${project.version}</version>
                  <type>ejb</type>
              </dependency>
          </dependencies>
      </project>
      

       

       

       

      Due to debugging I can see that the onMessage method of my MDB is reached after sending one message to a queue. But the desired messageHandler which shall be set by autowiring is still null.

      Also a debug point into the auto wired set-method is never reached.

       

      Autowiring on my web module works pretty fine.

       

      If you need any further information please ask fot it.

       

      Thanks in advance.