<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">

<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>

                                <td>

                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="https://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>

                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px;  -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
    Loading Spring annotated beans from AbstractSpringAction in ESB ActionPipeline
</h3>
<span style="margin-bottom: 10px;">
    created by <a href="https://community.jboss.org/people/bsingareddy">Bala Singareddy</a> in <i>JBoss ESB Development</i> - <a href="https://community.jboss.org/message/779710#779710">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p>Hi,</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; I have an issue loading Spring 3 Beans annotated with Stereotypes- @Component,@Repository,@Service.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; My current *applicationContext.xml* defined within the project has ComponentScanning enabled for a package using -</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; {code:xml}</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;context:annotation-config/&gt;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;context:component-scan base-package="classpath*:net.whatever.service"/&gt;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; {code}</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; 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 - </p><p>&#160; </p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; {code:xml}</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;service category="category" name="servicename"&gt;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;listeners&gt;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;jms-listener busidref="defined" name="listenername" /&gt;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;/listeners&gt;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;actions mep="OneWay"&gt;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;action name="actionname" class="net.whatever.custom.MySpringEnabledAction" process="processname"&gt;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;property name="springContextXml" value="applicationContext.xml"/&gt;&#160;&#160;&#160;&#160; </p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;action ... /&gt;&#160; </p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;/actions&gt;&#160; </p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;/service&gt;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; {code}</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; Here's a piece of code of how I'm implementing the MySpringEnabledAction.java class - </p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; {code}</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; public class MySpringEnabledAction extends AbstractSpringAction {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; public MySpringEnabledAction(ConfigTree _config){</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; configTree = _config;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; public processName ....</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; .....</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; {code}</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p> The problem I'm facing is with this now - </p><p> In the package *net.whatever.service* on which Spring does the ComponentScanning there is a class called MyServiceImpl.java which looks like this - </p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160; {code}</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; @Service(name="myservice_name")</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; public class MyServiceImpl implements MyService{</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ....</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ....</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p><p>&#160;&#160;&#160;&#160;&#160;&#160; {code}</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>MyService is an interface and there is no ambiguity between beans. This is the only Concrete implementation which implements this interface.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>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]... </p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>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 - </p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {code}</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; public class Receiver {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; protected MyService myservice</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; @Autowired</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; public class setMyService(MyService myservice){</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; this.myservice = myservice;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; .....</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; .....</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; } </p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {code}</p><p> 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.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p> 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. </p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>So could somebody help me figure out what the issue with the SpringContainer not pre-initializing the MyService Bean is?</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Thanks.</p></div>

<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
    <p style="margin: 0;">Reply to this message by <a href="https://community.jboss.org/message/779710#779710">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in JBoss ESB Development at <a href="https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2032">Community</a></p>
</div></td>
                        </tr>
                    </tbody>
                </table>


                </td>
            </tr>
        </tbody>
    </table>

</div>

</body>
</html>