jaxws:endpoint of CXF to fire up a JAX-WS service

The previous example of running a JAX-WS Web Service with Apache CXF 2.3.3 (as I described in the previous blog entry Learning Apache CXF with Eclipse and soapUI plugin) reminded me about CXF support for Spring Framework.

Run the following class:

package pl.jaceklaskowski.cxf;

import javax.jws.WebService;

import org.springframework.context.support.ClassPathXmlApplicationContext;

public class JaxWsServerFactoryBeanTest {

    public static void main(String[] args) {
        new ClassPathXmlApplicationContext(new String[] { "beans.xml" });

    public static class MyService {
        public int add(int x, int y) {
            return x + y;

with the



<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">

  <jaxws:endpoint id="myservice"


and this and the previous example will yield the same outcome.

More about jaxws:endpoint and relatives in the CXF documentation – JAX-WS Configuration.

On a aside, what troubles me is that I don’t really know what I’d need it for. Any guidance and use cases would be welcome.

Be Sociable, Share!
This entry was posted in Frameworks.

5 Responses to jaxws:endpoint of CXF to fire up a JAX-WS service

  1. Jacek, I’m not sure if thats what you’re asking for: an endpoint can be configured either in XML (as you did in this example) or with JAX-WS API (as you did in your previous post). I believe both methods are equivalent.

    • Jacek Laskowski says:

      My question was about the pros and cons of doing it. Why would I need to use jaxws:endpoint in beans.xml? What does it buy me? I think I’ll have to post the question to the CXF users mailing list. I’ll get it posted once received.

  2. Maciek says:

    Well, it all comes to the question: are you using spring in your application?

    If yes, then configuring cxf via spring makes perfect sense:
    1. you can wire dependencies (e.g. inject DAO/Service/whatever in your ws implementation)
    2. you can use spring configuration mechanisms and not hardcode ws url
    3. for ws clients you can use them (and inject) as any other spring bean
    4. probably some more reasons I can’t think of on saturday morning ;)

    If no, then I guess there is no real reason to start using spring just to configure cxf :)

    • Jacek Laskowski says:

      Let me rephrase the question since I learnt a little bit in the meantime – is there a reason to use CXF’s jaxws:endpoint over Spring Web Services’s remoting? The overwhelming number of options is slowly but continuously killing me.

      • Maciek says:

        That’s really a different question: Spring-WS vs. CXF.
        The main difference between them is that Spring-WS is NOT JAX-WS implementation. It is kind of more flexible – you don’t need to use JAXB, you can use custom dispatching of WS operations and so on. It also supports fewer WS-* specs than CXF.
        I think that for common use CXF is easier to start with, however Spring-WS flexibility is sometimes pretty useful.

Leave a Reply

%d bloggers like this: