WebService之Soap服务发布(一)

本文详细介绍如何使用Maven创建并发布WebService服务。首先,通过导入必要的Apache CXF依赖项来配置Maven项目。其次,定义一个简单的@WebService注解的Hello类,实现WebService接口。最后,通过main方法中的Endpoint.publish()函数发布服务到本地主机。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、新建一个Maven项目,并导入相应的依赖

    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-frontend-jaxws</artifactId>
        <version>2.2.3</version>
    </dependency>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-transports-http</artifactId>
        <version>2.2.3</version>
    </dependency>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-transports-http-jetty</artifactId>
        <version>2.2.3</version>
    </dependency>

二、新建一个WebService

package com.TheService.service;

import javax.jws.WebMethod;
import javax.jws.WebResult;
import javax.jws.WebService;

@WebService//标注为WebService
public class Hello {

	@WebMethod
	@WebResult(name="helloresult")
	public String hello() {
		return "Hello";
	}
}

三、新建一个main方法,发布WebService

package com.TheService;

import javax.xml.ws.Endpoint;

import com.TheService.service.Hello;

/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args )
    {
    	System.out.println("开始发布");
        Endpoint.publish("http://localhost:8088/hello", new Hello());//再一次发布中,一个端口可以发布多个WebService
         Endpoint.publish("http://localhost:8088/hello", new Hello());//再一次发布中,一个端口可以发布多个WebService
        System.out.println("发布成功");
        
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值