webservice java cxf_WebService -- Java 实现之 CXF ( 使用:Spring+CXF+Tomcat发布webService)

1. 新建一个Maven项目,选择webapp模板,命名为WS_Spring_CXF_Tomcat

3a8ae55d8a627bdbf2fe50a699a1f189.png

1a9614ae28c085b85b7d750873052690.png

2. 在POM.xml中添加Spring和CXF的依赖

org.springframework

spring-core

4.1.7.RELEASE

org.springframework

spring-beans

4.1.7.RELEASE

org.springframework

spring-tx

4.1.7.RELEASE

org.springframework

spring-context

4.1.7.RELEASE

org.springframework

spring-context-support

4.1.7.RELEASE

org.springframework

spring-web

4.1.7.RELEASE

org.springframework

spring-webmvc

4.1.7.RELEASE

org.springframework

spring-aop

4.1.7.RELEASE

org.springframework

spring-aspects

4.1.7.RELEASE

org.springframework

spring-jdbc

4.1.7.RELEASE

org.apache.cxf

cxf-core

3.1.5

org.apache.cxf

cxf-rt-frontend-jaxws

3.1.5

org.apache.cxf

cxf-rt-transports-http

3.1.5

3. 修改 project->src->main->web app->WEB-INFO->web.xml

指定spring配置和servlet配置:

WS_Spring_CXF_Tomcat

index.html

index.htm

index.jsp

default.html

default.htm

default.jsp

contextConfigLocation

classpath:applicationContext.xml

org.springframework.web.context.ContextLoaderListener

CXFServlet

org.apache.cxf.transport.servlet.CXFServlet

CXFServlet

/webservice/*

4. 添加Spring配置文件到classpath路径下

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns:p="http://www.springframework.org/schema/p"

xmlns:aop="http://www.springframework.org/schema/aop"

xmlns:context="http://www.springframework.org/schema/context"

xmlns:jee="http://www.springframework.org/schema/jee"

xmlns:tx="http://www.springframework.org/schema/tx"

xmlns:jaxws="http://cxf.apache.org/jaxws"

xsi:schemaLocation="

http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd

http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd

http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd

http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd

http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd

http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">

注意添加:

1.Spring和CXF名空间;

2.CXF配置文件

5.定义WebService接口及实现类

package com.example.tuo.webservice.impl;

import javax.jws.WebService;

import org.springframework.stereotype.Component;

import com.example.tuo.webservice.HelloWorld;

@Component("helloWorld")

@WebService

public class HelloWorldImpl implements HelloWorld{

public String sayHello(String sb) {

// TODO Auto-generated method stub

return "Hello world," +sb;

}

}

在实现类中添加 "@Component("helloWorld")" 注解,并且修改Spring配置文件(applicationContext.xml),利用Spring管理实现类

6.修改Spring配置文件,暴露微博service的endpoint

implementor="#helloWorld"

address="/HelloWorld">

7. 启动Tomcat,在浏览器中输入webservice的address

http://localhost:8080/WS_Spring_CXF_Tomcat/webservice/HelloWorld?wsdl

ab9769d8dc4230c829342297fb2028ef.png

OK, 这样我们就成功的讲webservice发布到了Tomcat上。 :)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值