zoukankan      html  css  js  c++  java
  • cxf简单实例

    CXF是一个基于 Servlet 技术的 SOA 应用开发框架,简单来说,就是WebService的轻量级实现。

    1、下载开发包:http://cxf.apache.org/download.html,选择相应的版本。

    2、在eclipse创建maven web工程。

    3、打开开发包实例的:java_first_spring_support,将java,resources, webapp复制到工程。

    4、复制pom.xml文件到工程,将工程名称修改成自己创建的工程,如:

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
      <modelVersion>4.0.0</modelVersion>
      <groupId>jaxws</groupId>
      <artifactId>jaxws</artifactId>
      <version>0.0.1-SNAPSHOT</version>
      <name>jaxws Maven Webapp</name>
      <description>Spring HTTP Sample</description>
      <packaging>war</packaging>
      
       <properties>
            <cxf.version>${project.version}</cxf.version>
            <cxf.release.base>${basedir}/../..</cxf.release.base>
        </properties>
        <build>
            <plugins>
                <plugin>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>2.1</version>
                    <configuration>
                        <webXml>src/main/webapp/WEB-INF/web.xml</webXml>
                    </configuration>
                </plugin>
            </plugins>
            <finalName>JavaFirstSpringSupport</finalName>
        </build>
        <profiles>
            <profile>
                <id>server</id>
                <build>
                    <defaultGoal>test</defaultGoal>
                    <plugins>
                        <plugin>
                            <groupId>org.codehaus.mojo</groupId>
                            <artifactId>exec-maven-plugin</artifactId>
                            <executions>
                                <execution>
                                    <phase>test</phase>
                                    <goals>
                                        <goal>java</goal>
                                    </goals>
                                    <configuration>
                                        <mainClass>demo.spring.service.Server</mainClass>
                                    </configuration>
                                </execution>
                            </executions>
                        </plugin>
                    </plugins>
                </build>
            </profile>
            <profile>
                <id>client</id>
                <build>
                    <defaultGoal>test</defaultGoal>
                    <plugins>
                        <plugin>
                            <groupId>org.codehaus.mojo</groupId>
                            <artifactId>exec-maven-plugin</artifactId>
                            <executions>
                                <execution>
                                    <phase>test</phase>
                                    <goals>
                                        <goal>java</goal>
                                    </goals>
                                    <configuration>
                                        <mainClass>demo.spring.client.Client</mainClass>
                                    </configuration>
                                </execution>
                            </executions>
                        </plugin>
                    </plugins>
                </build>
            </profile>
        </profiles>
        <dependencies>
            <dependency>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-rt-frontend-jaxws</artifactId>
                <version>2.7.16</version>
            </dependency>
            <dependency>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-rt-transports-http</artifactId>
                <version>2.7.16</version>
            </dependency>
            <dependency>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-rt-transports-http-jetty</artifactId>
                <version>2.7.16</version>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-context</artifactId>
                <version>3.0.7.RELEASE</version>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-web</artifactId>
                <version>3.0.7.RELEASE</version>
            </dependency>
            <dependency>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-webapp</artifactId>
                <version>8.1.5.v20120716</version>
            </dependency>
        </dependencies>
      
    </project>

    5、完成后目录结构如图:

    6、运行项目。

    7、配置resouces中client_bean.xml中地址符合你本地的服务,运行Client.java,访问成功。

    package demo.spring.client;
    
    import org.springframework.context.support.ClassPathXmlApplicationContext;
    
    import demo.spring.service.HelloWorld;
    
    
    public final class Client {
    
        private Client() {
        }
    
        public static void main(String args[]) throws Exception {
            // START SNIPPET: client
            ClassPathXmlApplicationContext context 
                = new ClassPathXmlApplicationContext(new String[] {"client-beans.xml"});
    
            HelloWorld client = (HelloWorld)context.getBean("client");
    
            String response = client.sayHi("Joe");
            System.out.println("Response: " + response);
            System.exit(0);
            // END SNIPPET: client
        }
    }
  • 相关阅读:
    UVA12206 Stammering Aliens 【SAM 或 二分 + hash】
    字符串hash
    BZOJ1064 [Noi2008]假面舞会 【dfs】
    BZOJ2333 [SCOI2011]棘手的操作 【离线 + 线段树】
    BZOJ1499 [NOI2005]瑰丽华尔兹 【单调队列优化dp】
    BZOJ3343 & 洛谷2801:教主的魔法——题解
    BZOJ2821:作诗——题解
    BZOJ2724:[Violet 6]蒲公英——题解
    BZOJ2653:middle——题解
    BZOJ2588:Count on a tree——题解
  • 原文地址:https://www.cnblogs.com/chrischen662/p/4589409.html
Copyright © 2011-2022 走看看