`
萧_瑟
  • 浏览: 161162 次
社区版块
存档分类
最新评论

基于CXF的webService本地数据交互----PC端与Android端(二)

    博客分类:
  • java
阅读更多

 

服务端以maven的形式创建项目。

 

项目创建好后,其结构如图:

 

关于客户端测试代码(PC和android端)和服务端的接口及实现代码可参考

基于CXF的webService本地数据交互----PC端与Android端(一)

代码不变。

 

用maven主要是包的导入问题(pom.xml),对于这块我试了好久啊。

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/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>

	<groupId>com.royal</groupId>
	<artifactId>cxf_webservice</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>jar</packaging>

	<name>cxf_webservice</name>
	<url>http://maven.apache.org</url>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
	</properties>

	<dependencies>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>3.8.1</version>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>aopalliance</groupId>
			<artifactId>aopalliance</artifactId>
			<version>1.0</version>
		</dependency>
		<dependency>
			<groupId>asm</groupId>
			<artifactId>asm</artifactId>
			<version>3.3</version>
		</dependency>
		<dependency>
			<groupId>commons-logging</groupId>
			<artifactId>commons-logging</artifactId>
			<version>1.1.1</version>
		</dependency>
		<!-- 这里由于连网下载不下来,可以手动下载CXF版本的包,然后自己手动加进去,添加的方法直接将cxf-2.4.6.jar放到.m2/repository/org/apache/cxf/cxf/2.4.6/的文件夹下。手动添加jar包都是这么干的。 -->
		<dependency>
			<groupId>org.apache.cxf</groupId>
			<artifactId>cxf</artifactId>
			<version>2.4.6</version>
		</dependency>
		<dependency>
			<groupId>org.apache.geronimo.specs</groupId>
			<artifactId>geronimo-activation_1.1_spec</artifactId>
			<version>1.1</version>
		</dependency>
		<dependency>
			<groupId>org.apache.geronimo.specs</groupId>
			<artifactId>geronimo-annotation_1.0_spec</artifactId>
			<version>1.1.1</version>
		</dependency>
		<dependency>
			<groupId>org.apache.geronimo.specs</groupId>
			<artifactId>geronimo-javamail_1.4_spec</artifactId>
			<version>1.7.1</version>
		</dependency>
		<!-- <dependency> -->
		<!-- <groupId>org.apache.geronimo.specs</groupId> -->
		<!-- <artifactId>geronimo-servlet_2.5_spec</artifactId> -->
		<!-- <version>1.1.2</version> -->
		<!-- </dependency> -->
		<dependency>
			<groupId>org.apache.geronimo.specs</groupId>
			<artifactId>geronimo-ws-metadata_2.0_spec</artifactId>
			<version>1.1.3</version>
		</dependency>
<!-- 		<dependency> -->
<!-- 			<groupId>javax.xml.bind</groupId> -->
<!-- 			<artifactId>jaxb-api</artifactId> -->
<!-- 			<version>2.2.3</version> -->
<!-- 		</dependency> -->
<!-- 		<dependency> -->
<!-- 			<groupId>com.sun.xml.bind</groupId> -->
<!-- 			<artifactId>jaxb-impl</artifactId> -->
<!-- 			<version>2.2.4-1</version> -->
<!-- 		</dependency> -->
		<dependency>
			<groupId>org.apache.neethi</groupId>
			<artifactId>neethi</artifactId>
			<version>3.0.1</version>
		</dependency>
		<!-- 这个也是手动添加的 -->
		<dependency>
			<groupId>org.mortbay.jetty</groupId>
			<artifactId>jetty-util</artifactId>
			<version>7.4.5.v20110725</version>
		</dependency>
<!-- 		<dependency> -->
<!-- 			<groupId>javax.xml.soap</groupId> -->
<!-- 			<artifactId>saaj-api</artifactId> -->
<!-- 			<version>1.3.4</version> -->
<!-- 		</dependency> -->
<!-- 		<dependency> -->
<!-- 			<groupId>com.sun.xml.messaging.saaj</groupId> -->
<!-- 			<artifactId>saaj-impl</artifactId> -->
<!-- 			<version>1.3.12</version> -->
<!-- 		</dependency> -->
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-aop</artifactId>
			<version>3.1.0.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-beans</artifactId>
			<version>3.1.0.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-asm</artifactId>
			<version>3.1.0.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-core</artifactId>
			<version>3.1.0.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-context</artifactId>
			<version>3.1.0.RELEASE</version>
		</dependency>
		<!-- spring-web包一加载,老是报这个错:org.xml.sax.SAXParseException: The entity "nbsp" was referenced, but not declared.--> 
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-web</artifactId>
			<version>3.1.0.RELEASE</version>  
		</dependency>
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-expression</artifactId>
			<version>3.1.0.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.codehaus.woodstox</groupId>
			<artifactId>stax2-api</artifactId>
			<version>3.1.1</version>
		</dependency>
		<dependency>
			<groupId>wsdl4j</groupId>
			<artifactId>wsdl4j</artifactId>
			<version>1.6.2</version>
		</dependency>
		<dependency>
			<groupId>org.apache.ws.xmlschema</groupId>
			<artifactId>xmlschema-core</artifactId>
			<version>2.0.1</version>
		</dependency>
	</dependencies>
</project>
 
org.xml.sax.SAXParseException: The entity "nbsp" was referenced, but not declared.

报这个错其实可以不用理他,做的时候我还一直纠结着,具体怎么解决我还是也不知道。

maven从网上下载包请取消Offline选项

最后down下来的包有这些

 
beanRefServer.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 Apache CXF Bean Definition -->
	<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" />

	<!-- implementor :接口类的实现类 address: 要和注释里面神秘的服务名对应, -->
	<jaxws:endpoint id="helloWorld"
		implementor="com.royal.serviceImpl.HelloWorldImpl" address="/HelloWorldService" />

</beans>

 

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">
	
	<!-- Spring Config Location -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/beanRefServer.xml</param-value>
    </context-param>
    Spring ContextLoaderListener
    <listener>
        <listener-class>
            org.springframework.web.context.ContextLoaderListener
        </listener-class>
    </listener>
    
     <!-- Apache CXFServlet -->
    <servlet>
        <servlet-name>CXFServlet</servlet-name>
        <servlet-class>
            org.apache.cxf.transport.servlet.CXFServlet
        </servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <!-- CXFServlet Mapping -->
    <servlet-mapping>
        <servlet-name>CXFServlet</servlet-name>
        <url-pattern>/services/*</url-pattern>
    </servlet-mapping>
	
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>

 

项目文件所有都OK后,maven的部署,注意一定要清楚缓存啊。一个干净的环境很重要。

 

右键项目---属性---tomcat

注意勾选部署前的jar包

再来2步操作

project---clean,  project----update all maven dependencies

 

这下干净了,启动Tomcat。

 

测试结果

  • 大小: 21.3 KB
  • 大小: 81.8 KB
  • 大小: 23.7 KB
  • 大小: 5.6 KB
  • 大小: 51.2 KB
  • 大小: 96.8 KB
分享到:
评论

相关推荐

    基于CXF的webService本地数据交互----PC端与Android端(一)

    本文将深入探讨基于Apache CXF实现的Web Service在本地数据交互中的应用,尤其是如何在PC端与Android端之间进行通信。Apache CXF是一个开源框架,专门用于构建和消费Web服务,支持多种协议和标准,如SOAP、RESTful等...

    基于CXF的webService本地数据交互----PC端与Android端(三)

    在本篇博文中,我们将深入探讨如何利用Apache CXF库创建一个基于Web Service的数据交互解决方案,特别是关注于PC端和Android端之间的本地通信。Apache CXF是一个开源框架,它允许开发者构建和部署SOAP(简单对象访问...

    基于CXF的webService本地数据交互----PC端(四)

    在本篇博文中,我们将深入探讨如何利用Apache CXF库创建和实现基于Web Service的本地数据交互,特别是在PC端的应用。Apache CXF是一个开源框架,它允许开发者构建和部署服务,支持多种Web服务规范,如SOAP、RESTful...

    cxf-rt-rs-client-3.0.1-API文档-中文版.zip

    赠送jar包:cxf-rt-rs-client-3.0.1.jar; 赠送原API文档:cxf-rt-rs-client-3.0.1-javadoc.jar; 赠送源代码:cxf-rt-rs-client-3.0.1-sources.jar; 赠送Maven依赖信息文件:cxf-rt-rs-client-3.0.1.pom; 包含...

    cxf-rt-transports-http-3.0.1-API文档-中文版.zip

    赠送jar包:cxf-rt-transports-http-3.0.1.jar; 赠送原API文档:cxf-rt-transports-http-3.0.1-javadoc.jar; 赠送源代码:cxf-rt-transports-http-3.0.1-sources.jar; 赠送Maven依赖信息文件:cxf-rt-transports-...

    cxf-rt-frontend-jaxrs-3.0.1-API文档-中文版.zip

    赠送jar包:cxf-rt-frontend-jaxrs-3.0.1.jar; 赠送原API文档:cxf-rt-frontend-jaxrs-3.0.1-javadoc.jar; 赠送源代码:cxf-rt-frontend-jaxrs-3.0.1-sources.jar; 赠送Maven依赖信息文件:cxf-rt-frontend-jaxrs...

    cxf-rt-frontend-simple-3.0.1-API文档-中文版.zip

    赠送jar包:cxf-rt-frontend-simple-3.0.1.jar; 赠送原API文档:cxf-rt-frontend-simple-3.0.1-javadoc.jar; 赠送源代码:cxf-rt-frontend-simple-3.0.1-sources.jar; 赠送Maven依赖信息文件:cxf-rt-frontend-...

    cxf-rt-frontend-jaxws-3.0.1-API文档-中文版.zip

    赠送jar包:cxf-rt-frontend-jaxws-3.0.1.jar; 赠送原API文档:cxf-rt-frontend-jaxws-3.0.1-javadoc.jar; 赠送源代码:cxf-rt-frontend-jaxws-3.0.1-sources.jar; 赠送Maven依赖信息文件:cxf-rt-frontend-jaxws...

    cxf-rt-databinding-jaxb-3.0.1-API文档-中文版.zip

    赠送jar包:cxf-rt-databinding-jaxb-3.0.1.jar; 赠送原API文档:cxf-rt-databinding-jaxb-3.0.1-javadoc.jar; 赠送源代码:cxf-rt-databinding-jaxb-3.0.1-sources.jar; 赠送Maven依赖信息文件:cxf-rt-...

    cxf-rt-bindings-soap-3.0.1-API文档-中文版.zip

    赠送jar包:cxf-rt-bindings-soap-3.0.1.jar; 赠送原API文档:cxf-rt-bindings-soap-3.0.1-javadoc.jar; 赠送源代码:cxf-rt-bindings-soap-3.0.1-sources.jar; 赠送Maven依赖信息文件:cxf-rt-bindings-soap-...

    cxf-core-3.0.1-API文档-中文版.zip

    赠送jar包:cxf-core-3.0.1.jar; 赠送原API文档:cxf-core-3.0.1-javadoc.jar; 赠送源代码:cxf-core-3.0.1-sources.jar; 赠送Maven依赖信息文件:cxf-core-3.0.1.pom; 包含翻译后的API文档:cxf-core-3.0.1-...

    WebService CXF --- 传输文件MTOM

    WebService CXF,全称Apache CXF,是一款开源的Java框架,用于构建和开发Web服务。它支持多种协议和规范,包括SOAP、RESTful、XML以及Web服务标准如WS-*。在"WebService CXF --- 传输文件MTOM"这个主题中,我们将...

    cxf-rt-rs-extension-providers-3.0.1-API文档-中文版.zip

    赠送jar包:cxf-rt-rs-extension-providers-3.0.1.jar; 赠送原API文档:cxf-rt-rs-extension-providers-3.0.1-javadoc.jar; 赠送源代码:cxf-rt-rs-extension-providers-3.0.1-sources.jar; 赠送Maven依赖信息...

    cxf-rt-bindings-xml-3.0.1-API文档-中文版.zip

    赠送jar包:cxf-rt-bindings-xml-3.0.1.jar; 赠送原API文档:cxf-rt-bindings-xml-3.0.1-javadoc.jar; 赠送源代码:cxf-rt-bindings-xml-3.0.1-sources.jar; 赠送Maven依赖信息文件:cxf-rt-bindings-xml-3.0.1....

    cxf-rt-ws-addr-3.0.1-API文档-中文版.zip

    赠送jar包:cxf-rt-ws-addr-3.0.1.jar; 赠送原API文档:cxf-rt-ws-addr-3.0.1-javadoc.jar; 赠送源代码:cxf-rt-ws-addr-3.0.1-sources.jar; 赠送Maven依赖信息文件:cxf-rt-ws-addr-3.0.1.pom; 包含翻译后的API...

    cxf-rt-frontend-jaxws-3.0.16.jar 下载

    cxf-rt-frontend-jaxws-3.0.16.jar jar包下载3.0.16版本下载

Global site tag (gtag.js) - Google Analytics