|
Page Edited :
CXF20DOC :
Writing a service with Spring
Writing a service with Spring has been edited by jeffreyhsu (Nov 19, 2007). Content:This example will lead you through creating your first service with Spring
This example corresponds to the spring_http example in the CXF distribution. Setting up your buildOpen up your favorite IDE and create a new project. The first thing we need to do is add the necessary CXF dependencies to the project. You can find these dependencies in the CXF distribution in the lib directory. commons-logging-1.1.jar geronimo-activation_1.1_spec-1.0-M1.jar (or Sun's Activation jar) geronimo-annotation_1.0_spec-1.1.jar (JSR 250) geronimo-javamail_1.4_spec-1.0-M1.jar (or Sun's JavaMail jar) geronimo-servlet_2.5_spec-1.1-M1.jar (or Sun's Servlet jar) geronimo-ws-metadata_2.0_spec-1.1.1.jar (JSR 181) jaxb-api-2.0.jar jaxb-impl-2.0.5.jar jaxws-api-2.0.jar neethi-2.0.jar saaj-api-1.3.jar saaj-impl-1.3.jar stax-api-1.0.1.jar wsdl4j-1.6.1.jar wstx-asl-3.2.1.jar XmlSchema-1.2.jar xml-resolver-1.2.jar
To provide a bean name instead of a classname as an implementor, simply supply the bean-name prepended with "#", e.g. implementor="#myBean". Setting up the ServletWe'll need to add two things to our web.xml file:
It is important to note that the address that you chose for your endpoint bean must be one your servlet listens on. For instance, if my Servlet was register for "/some-services/*" but my address was "/more-services/HelloWorld", there is no way CXF could receive a request. Create a ClientCXF includes a JaxWsProxyFactory bean which create a client for you from your service interface. You simply need to tell it what your service class is (the HelloWorld interface in this case) and the URL of your service. You can then create a client bean via the JaxWsProxyFactory bean by calling it's create() method. Here's an example: <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schema/jaxws.xsd"> <bean id="client" class="demo.spring.HelloWorld" factory-bean="clientFactory" factory-method="create"/> <bean id="clientFactory" class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean"> <property name="serviceClass" value="demo.spring.HelloWorld"/> <property name="address" value="http://localhost:9002/HelloWorld"/> </bean> </beans> If you were going to access your client you could now simply pull it out of the Spring context (or better yet, inject it into your application using Spring!): ApplicationContext context = ...; // your Spring ApplicationContext HellWorld client = (HelloWorld) context.getBean("client"); Advanced StepsFor more information on using Spring you may want to read the Configuration and Spring sections of the User's Guide. |
Unsubscribe or edit your notifications preferences
