0 Replies Latest reply on Dec 3, 2012 3:15 PM by Bala Singareddy

    Loading Spring annotated beans from AbstractSpringAction in ESB ActionPipeline

    Bala Singareddy Newbie

      Hi,

       

      I have an issue loading Spring 3 Beans annotated with Stereotypes- @Component,@Repository,@Service.

       

              My current *applicationContext.xml* defined within the project has ComponentScanning enabled for a package using -

             {code:xml}

             <context:annotation-config/>

              <context:component-scan base-package="classpath*:net.whatever.service"/>

             {code}

       

       

      I'm using the JBoss ESB 4.11 Server. Here I have a ServicePipeline which takes in an Action with an ActionClass extending the AbstractSpringAction that loads the SpringContext. Here's how I'm doing this -

       

       

            {code:xml}

            <service category="category" name="servicename">

               <listeners>

               <jms-listener busidref="defined" name="listenername" />

               </listeners>

                <actions mep="OneWay">

                <action name="actionname" class="net.whatever.custom.MySpringEnabledAction" process="processname">

                    <property name="springContextXml" value="applicationContext.xml"/>    

                <action ... /> 

                </actions> 

               </service>

             {code}

       

              Here's a piece of code of how I'm implementing the MySpringEnabledAction.java class -

       

       

      {code}

      public class MySpringEnabledAction extends AbstractSpringAction {

                           public MySpringEnabledAction(ConfigTree _config){

                                   configTree = _config;

                              }

                          public processName ....

                                 .....

                  }

      {code}

       

       

      The problem I'm facing is with this now -

      In the package *net.whatever.service* on which Spring does the ComponentScanning there is a class called MyServiceImpl.java which looks like this -

       

      {code}

                   @Service(name="myservice_name")

                  public class MyServiceImpl implements MyService{

                       ....

                       ....

                   }

             {code}

       

       

      MyService is an interface and there is no ambiguity between beans. This is the only Concrete implementation which implements this interface.

       

      This annotation is not being seen or not being detected because this Bean is not being Pre-initialized by the Spring Container.. as a result I keep getting an error of org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [net.whatever.service.MyService]...

       

      This error pops-up because there is another Bean which is trying to use @Autowired annotation and injecting the MyService Bean into its implementation. This other bean looks like this -

       

      {code}

                               public class Receiver {

                                        protected MyService myservice

                                      @Autowired

                                          public class setMyService(MyService myservice){

                                               this.myservice = myservice;

                                          }

                                     .....

                                     .....

                               }

                         {code}

       

      This bean is also loaded by Spring but the difference here is its not part of the ComponentScanning that Spring will use.. it has a bean definition as XML configuration within the applicationContext.xml.

       

      All the Spring configuration worked fine when I deployed it as a WAR and used the Servlet context to load the Spring Context.. but now with this ESB Action loading the SpringContext.. all the basic annotations are falling apart.

       

      So could somebody help me figure out what the issue with the SpringContainer not pre-initializing the MyService Bean is?

       

      Thanks.