cxf搭建webservice helloworld

第一步:

 

package com.cxf;

public interface HelloWorld {
	String sayHello(String str);
}

 

package com.cxf;

import javax.jws.WebService;

@WebService
public class HelloWorldImpl implements HelloWorld {

	public String sayHello(String str) {
		System.out.println("你好:" + str);
		return "你好:" + str;
	}

}

 

 

第二步: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>test_cxf</groupId>
  <artifactId>com.cxf</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>com.cxf Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <properties>
    
    <cxf.version>2.7.5</cxf.version>
  </properties>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <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>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-transports-http-jetty</artifactId>
        <version>${cxf.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aop</artifactId>
        <version>3.2.3.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-beans</artifactId>
        <version>3.2.3.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context-support</artifactId>
        <version>3.2.3.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>3.2.3.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>3.2.3.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>3.2.3.RELEASE</version>
    </dependency>
  </dependencies>
  <build>
    <finalName>com.cxf</finalName>
  </build>
</project>

 

 第三步,在WEB-INF下新建cxf-servlet.xml

<?xml version="1.0" encoding="UTF-8"?>
<!-- START SNIPPET: beans -->   
<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.xsd   
    http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">   
    <import resource="classpath:META-INF/cxf/cxf.xml"/>   
    <import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>   
    <jaxws:endpoint id="hi" implementor="com.cxf.HelloWorldImpl" address="/hi"/>   
</beans>   
<!-- END SNIPPET: beans -->

 第四步,修改web.xml

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
  <display-name>Archetype Created Web Application</display-name>
  <servlet>
        <display-name>cxf</display-name>   
        <servlet-name>cxf</servlet-name>   
        <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
        <init-param>
			<!-- 配置Spring的配置文件 -->
			<param-name>config-location</param-name>
			<param-value>WEB-INF/cxf-servlet.xml</param-value>
	    </init-param>  
        <load-on-startup>1</load-on-startup>   
    </servlet>   
    <servlet-mapping>   
        <servlet-name>cxf</servlet-name>   
        <url-pattern>/ws/*</url-pattern>   
    </servlet-mapping>   
</web-app>

 输入地址:http://localhost:8008/cxf/ws/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值