java 写一个webservice接口(部署到Tomcat下)

java 写一个webservice接口(部署到Tomcat下)

  1. 创建一个web项目(我的是一个maven项目)
  2. 添加jar包

		
			junit
			junit
			3.8.1
			test
		
 
        
		
			org.apache.cxf
			apache-cxf
			3.2.6
			pom
			
				
					cxf-services-wsn-api
					org.apache.cxf.services.wsn
				
				
					cxf-services-wsn-core
					org.apache.cxf.services.wsn
				
				
					cxf-services-ws-discovery-api
					org.apache.cxf.services.ws-discovery
				
				
					cxf-services-ws-discovery-service
					org.apache.cxf.services.ws-discovery
				
			
		
	
  1. 添加web.xml


 
	
		Apache CXF Endpoint
		cxf
		cxf
		org.apache.cxf.transport.servlet.CXFServlet
		1
	
	
		cxf
		/services/*
	

  1. 写一个接口
import javax.jws.WebService;
@WebService
public interface MsgService {
	public String getValue(String name);
}
  1. 写接口的实现类
package com.msg.webservice.impl;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import javax.jws.WebService;
import com.msg.util.Log_Exception;
import com.msg.util.UrlUtil;
import com.msg.util.Util;
import com.msg.webservice.MsgService;
@WebService(endpointInterface = "com.msg.webservice.MsgService")
public class MsgServiceImpl implements MsgService {
	public String getValue(String name) {
		return "我叫" + name;
	}
}

  1. cxf-servlet.xml


 
	
	
 //implementor:实现类的地址	address:调用时的地址
	
 


  1. client-beans.xml


 //class:接口地址
	

	
		 //value:接口地址
		
		//value:调用时的地址
		
	

8.启动Tomcat
9.在浏览器输入
http://192.168.1.10:9090/MSService/services/msgservice?wsdl
java 写一个webservice接口(部署到Tomcat下)_第1张图片
10.调用接口
博客地址:https://blog.csdn.net/qq_40002311/article/details/82979720

你可能感兴趣的:(java)