WebService 开发步骤

WebService

这玩意具体是干嘛的呢? 大致意思是: 给外界提供一个接口,然后可以生成客户端去获取已经设定好的数据(大概这么个意思...一个月前写的小模块忘得差不多了,赶紧记下来,免得忘记),比如天气预报、百度翻译、设定好接口以后,传入数据,让百度翻译去翻译,然后咱们获得处理好的数据


开发WebService项目,先导入WebService的jar包...

添加bean.xml


<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	   xmlns:jaxws="http://cxf.apache.org/jaxws"
	   xmlns:tx="http://www.springframework.org/schema/tx" 
	   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/jaxws">
	   
	   <!-- 这边是引入CXF的核心配置 -->
	   <import resource="classpath:META-INF/cxf/cxf.xml"/>
	   <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml"/>
	   <import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>

	   <jaxws:endpoint
	   		id="upload" //id名字好像是和接口方法名字,我靠,特么的竟然忘记了...后面慢慢测吧
	   		implementor="server.ServerInterfaceImpl" //包名.接口类名
	   		address="/upload">//上下一致
	   </jaxws:endpoint>
	   
</beans>


然后写一个接口,在接口上面加上注解,像这样子...

@WebService
public interface ServerInterface {
	
	@WebMethod
	public String upload(String uploadRequest);
   }


然后再web.xml配置

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 
	xmlns="http://java.sun.com/xml/ns/javaee" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
	http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
  	<servlet>
  		<servlet-name>config</servlet-name>
  		<servlet-class>readerxml_local.InitializerServlet</servlet-class>
  		
		<load-on-startup>1</load-on-startup>
  	</servlet>
  	
  	  	<!-- 配置bean.xml -->
  	<context-param>
  		<param-name>contextConfigLocation</param-name>
  		<param-value>classpath:bean.xml</param-value>
  	</context-param>
  	
  	  	<!-- 启动一个监听器 -->
  	<listener>
  		<listener-class>
  			org.springframework.web.context.ContextLoaderListener
  		</listener-class>
  	</listener>
  	
  	  	<servlet>
  		<servlet-name>CXFServlet</servlet-name>
  		<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
  		<load-on-startup>1</load-on-startup>
  	</servlet>
  	<servlet-mapping>
  		<servlet-name>CXFServlet</servlet-name>
  		<url-pattern>/*</url-pattern>
  	</servlet-mapping>
  	
</web-app>


然后该干嘛干嘛...写接口..写JAVA代码去吧.....


好像就这几步吧...还真给忘记了,看来得及时记录啊....

欢迎指正!







你可能感兴趣的:(Web,service)