CXF 2.2.3

1.IDE:
      netBeans ide 6.7
      maven 2.09 +
2.create maven project with WebApp
3.modify pom.xml

<properties>
        <jetty-version>6.1.9</jetty-version>
        <cxf-version>2.2.3</cxf-version>
    </properties>
 ...
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-frontend-jaxws</artifactId>
            <version>${cxf-version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-transports-http</artifactId>
            <version>${cxf-version}</version>
        </dependency>
4. configurate complication with java1.5 
 in <build> <plugins> add:
      <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.5</source>
                    <target>1.5</target>
                </configuration>
            </plugin>
5.configurate Jetty for mvn jetty:run
           <plugin>
                <groupId>org.mortbay.jetty</groupId>
                <artifactId>maven-jetty-plugin</artifactId>
                <version>${jetty-version}</version>
                <configuration>
                    <stopPort>9009</stopPort> <!-- we can use mvn jetty:stop to stop jetty. we can not stop jetty in netbeans. -->
                    <stopKey>STOPCXF</stopKey>
                </configuration>
            </plugin>
6. configruatin java to wsdl

 <plugin>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-java2ws-plugin</artifactId>
                <version>${cxf-version}</version>
                <dependencies>
                    <dependency>
                        <groupId>org.apache.cxf</groupId>
                        <artifactId>cxf-rt-frontend-jaxws</artifactId>
                        <version>${cxf-version}</version>
                    </dependency>
                    <dependency>
                        <groupId>org.apache.cxf</groupId>
                        <artifactId>cxf-rt-frontend-simple</artifactId>
                        <version>${cxf-version}</version>
                    </dependency>
                </dependencies>

                <executions>
                    <execution>
                        <id>process-classes</id>
                        <phase>process-classes</phase>
                        <configuration>
                            <className>com.yy.cxf.HelloWorld</className>
                            <genWsdl>true</genWsdl>
                            <verbose>true</verbose>
                            <outputFile>src/main/webapp/WEB-INF/wsdl/helloworld.wsdl</outputFile>
                        </configuration>
                        <goals>
                            <goal>java2ws</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

7.config web.xml in /WEB-INF/
      (1)configurate listener of spring context:  org.springframework.web.context.ContextLoaderListener
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
      (2)configurate context parameter:
      <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:cxf-config.xml</param-value>
    </context-param>
      (3) configurate CXF servlet
      <servlet>
        <servlet-name>CXFServlets</servlet-name>
        <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>CXFServlets</servlet-name>
        <url-pattern>/webservice/*</url-pattern>
    </servlet-mapping>
8. create webservice inferface. HelloWorld.java
      @WebService
      public interface HelloWorld {
                public String sayHello(String name);
      }
9. HelloWorldImpl.java
    

      @WebService(endpointInterface="com.yy.cxf.HelloWorld",  serviceName="HelloWorldService")
      public class HelloWorldImpl implements HelloWorld {

          public String sayHello(String name) {
              System.out.println("we say hello to " + name);
              return "Hello " + name;
          }

      }


10. create cxf-config.xml in src/main/resources, config it
      add namespace.   xmlns:jaxws="http://cxf.apache.org/jaxws"
                                xsi:schemaLocation=" http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"

      add import:
             <import resource="classpath:META-INF/cxf/cxf.xml" />
             <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
             <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
      config endpoint:
      <jaxws:endpoint id="hellowordEndpoint"
              implementor="com.yy.cxf.HelloWorldImpl"
              address="/helloworld"  />
11. run: mvn jetty:run
12: access in broswer: http://localhost:8080/cxf/webservice/helloworld?wsdl
13: done.
posted @ 2009-08-28 16:06  思粮  阅读(1092)  评论(0编辑  收藏  举报