日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

CXF2.7.3 与spring 3集成 .

發(fā)布時(shí)間:2025/7/14 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 CXF2.7.3 与spring 3集成 . 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

1 需要的jar包

cxf包括:cxf-2.7.3.jar? wsdl4j-1.6.2.jar? xmlschema-core-2.0.3.jar? neethi-3.0.2.jar httpasyncclient-4.0-beta3.jar httpclient-4.2.1.jar httpcore-4.2.2.jar httpcore-nio-4.2.2.jar

spring包括:spring-aop-3.0.7.RELEASE.jar spring-asm-3.0.7.RELEASE.jar spring-beans-3.0.7.RELEASE.jar spring-context-3.0.7.RELEASE.jar spring-core-3.0.7.RELEASE.jar spring-expression-3.0.7.RELEASE.jar spring-jms-3.0.7.RELEASE.jar spring-tx-3.0.7.RELEASE.jar spring-web-3.0.7.RELEASE.jar

其它:commons-logging-1.1.1.jar

?

2 在web.xml填加以下配置

?<?xml version="1.0" encoding="UTF-8"?>?
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"?
??? xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"?
??? xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee???
??? http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">?
??? <context-param>?
??????? <param-name>contextConfigLocation</param-name>?
??????? <param-value>classpath:spring-cxf.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>/webservice/*</url-pattern>????
??? </servlet-mapping>?
</web-app>

?

3 創(chuàng)建服務(wù)端webservice類

1)創(chuàng)建IHelloWorld接口

import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;

@WebService
public interface IHelloWorld {
?public String sayHello(String name);
}

2)創(chuàng)建IHelloWorld接口的實(shí)現(xiàn)類HelloWorldImpl

import javax.jws.WebService;


public class HelloWorldImpl implements IHelloWorld {

?@Override
?public String sayHello(String name) {
??System.out.println("say hello is called");
??return "hello "+name;
?}

}

4)創(chuàng)建客戶端訪問webservice類

import org.springframework.context.ApplicationContext;

public class Client {
?public static void main(String[] args){

??ApplicationContext context = new ClassPathXmlApplicationContext("spring-cxf.xml");?
??IHelloWorld helloWorld=(IHelloWorld)context.getBean("helloWorldClient");
??System.out.println(helloWorld.sayHello("Test"));
?}
}

?

3 創(chuàng)建spring配置文件spring-cxf.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:tx="http://www.springframework.org/schema/tx"
?xmlns:aop="http://www.springframework.org/schema/aop" 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-3.0.xsd
?http://www.springframework.org/schema/tx
?http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
?http://www.springframework.org/schema/aop
?http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
??? http://www.springframework.org/schema/context
?http://www.springframework.org/schema/context/spring-context-3.0.xsd
?http://cxf.apache.org/jaxws
?
http://cxf.apache.org/schemas/jaxws.xsd"

?????????? <!--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"/>

????????

?????????? <!--服務(wù)端發(fā)布的webservice-->
?????????? <jaxws:endpoint id="helloWorld" implementor="openProjectTest.cxf.HelloWorldImpl" address="/HelloWorld"/>

?

?????????? <!--客戶端調(diào)用的webservice-->
?????????? <jaxws:client id="helloWorldClient" address="http://localhost:8080/web工程名/webservice/HelloWorld" serviceClass="openProjectTest.cxf.IHelloWorld"/>

</beans>

?

4 測試

1)訪問以下地址驗(yàn)證服務(wù)端是否配制成功

http://localhost:8080/web工程名/webservice/HelloWorld?wsdl? 如果可看到wsdl的xml文件則成功

http://localhost:8080/web工程名/webservice? 直接訪問該地址可查看系統(tǒng)提供幾個(gè)webservice服務(wù)

2)運(yùn)行Client類輸出 hello Test 則客戶端連接成功

總結(jié)

以上是生活随笔為你收集整理的CXF2.7.3 与spring 3集成 .的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。