apache CXF 的创建需要几十个jar包依赖, 对于新手来说可能就是跳不完的坑 ,不断的查找jar下载jar 我当然也是这样一步步的跳了无数的坑,不过还好最终我成功了!
如下图是jar包依赖:
链接: http://pan.baidu.com/s/1hqnH2eg 密码: y4vw
你可能不相信 ,难道真的需要吗?这么多依赖包 ?
答案是肯定的,真的是这样的,一个也不能少 ,真心的建议大家使用maven进行项目管理,你将体会maven给你带来的所有便利!!!!!!!
几行pom 搞定一切,so easy !
这些包搞定之后 就需要跟 spring 整合了(生命本人用的spring为4.x apache CXF 3.0),其实整合很简单的,废话不多说 上图如下:
需要引入配置文件的头信息如下:
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" 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://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
注意那几个cxf的就好了
web.xml需要配置servlet:
<web-app 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" version="2.5"> <display-name>DataCollector</display-name> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath*:config/applicationContext-*.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <servlet> <servlet-name>collector</servlet-name> <servlet-class> org.springframework.web.servlet.DispatcherServlet </servlet-class> </servlet> <servlet-mapping> <servlet-name>collector</servlet-name> <url-pattern>/rest/*</url-pattern> </servlet-mapping> <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>/ws/*</url-pattern> </servlet-mapping> </web-app>
配置完了 我们看看具体的类和注解:
@WebService(endpointInterface = "cn.com.flaginfo.ws.interfaces.HelloWebService") public class HelloWebserviceImpl implements HelloWebService{ @Override public String greeting(String s) { return "Hello World!"; } @Override public String greeting2() { // TODO Auto-generated method stub return "dd"; } }
@WebService public interface HelloWebService { public String greeting(String s); public String greeting2(); } good luck 本人的QQ827741251欢迎交流!
时间: 2024-10-29 18:44:20