<!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;">
CXF Endpoint not autowiring spring beans
</h3>
<span style="margin-bottom: 10px;">
created by <a href="https://community.jboss.org/people/skunjumohamed">Shameer Kunjumohamed</a> in <i>JBoss Web Services</i> - <a href="https://community.jboss.org/message/753601#753601">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 style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>CXF endpoint is not properly integrated with spring. I am using JBoss AS 7.1.1 to deploy my cxf webservice integrated with spring. The log messages shows that both CXF and spring creates two different instances of the endpoint bean, and only the spring-created bean is autowired. </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>The CXF created instance does not have the dependencies set and it is the one who listens to the client requests, and throws null pointers.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Here is the code..</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Service Interface..</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>package test.cxf.service;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>import javax.jws.WebMethod;</p><p>import javax.jws.WebParam;</p><p>import javax.jws.WebService;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><span>@WebService(name = "EchoService", targetNamespace = "</span><a class="jive-link-external-small" href="http://service.cxf.test/" target="_blank">http://service.cxf.test/</a><span>")</span></p><p>public interface EchoService {</p><p>    </p><p>    @WebMethod(operationName = "echo", action = "urn:Echo")</p><p>    String echo(@WebParam(name = "message") String message);</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>}</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Service implementation (Endpoint)</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>package test.cxf.service;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>import javax.jws.WebMethod;</p><p>import javax.jws.WebParam;</p><p>import javax.jws.WebResult;</p><p>import javax.jws.WebService;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>import org.springframework.beans.factory.annotation.Autowired;</p><p>import org.springframework.beans.factory.annotation.Value;</p><p>import org.springframework.stereotype.Service;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>@Service("EchoService")</p><p>@WebService(endpointInterface = "test.cxf.service.EchoService", serviceName = "EchoService")</p><p>public class EchoServiceImpl implements EchoService {</p><p>    </p><p>    @Autowired</p><p>    private SystemInfoBean sysInfoBean;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>    public EchoServiceImpl() {</p><p>        System.out.println("&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; " + this.getClass().getName() + "-constructed.");</p><p>    }</p><p>    </p><p>    @Value("Fooooooooooooo Baaaaaaaaaar")</p><p>    public void setTestInjection(String value) {</p><p>        System.out.println("&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Test Injection value = " + value);</p><p>    }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>    @WebMethod</p><p>    public @WebResult(name="result") String echo(@WebParam(name="message") String message) {</p><p>        System.out.println("&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; Inside " + this.getClass().getClass().getName() + "-echo - message = " + message);</p><p>        System.out.println(" Echoing " + message);</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>        sysInfoBean.printOSInfo();</p><p>        </p><p>        return message;</p><p>    }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>}</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>SystemInfoBean - A dependent bean</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>package test.cxf.service;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>import java.lang.management.ManagementFactory;</p><p>import java.lang.management.OperatingSystemMXBean;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>import org.springframework.stereotype.Component;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>@Component</p><p>public class SystemInfoBean {</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>    public SystemInfoBean() {</p><p>        // TODO Auto-generated constructor stub</p><p>    }</p><p>    </p><p>    public void printOSInfo() {</p><p>        OperatingSystemMXBean osXBean = ManagementFactory.getOperatingSystemMXBean();</p><p>        System.out.println("============ Operating System Information=========");</p><p>        System.out.println("Operating System: " + osXBean.getName());</p><p>        System.out.println("Version: " + osXBean.getVersion());</p><p>        System.out.println("Architecture: " + osXBean.getArch());</p><p>        System.out.println("Available Processors: " + osXBean.getAvailableProcessors());</p><p>        System.out.println("==================================================");</p><p>    }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>}</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Spring configuration (beans.xml)</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>web.xml</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>I am excluding the JBoss CXF modules or implementation jars in the jboss-deployment-structure.xml</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Thanks for any help in advance.</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/753601#753601">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in JBoss Web Services at <a href="https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2044">Community</a></p>
</div></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>