最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Java?WebService開源框架CXF詳解

 更新時間:2021年12月12日 12:42:17   作者:春水上行  
本文詳細講解了Java?WebService開源框架CXF,文中通過示例代碼介紹的非常詳細。對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

CXF簡介

CXF是一個開源的WebService框架。Apache CXF = Celtix + XFire,開始叫 Apache CeltiXfire,后來更名為 Apache CXF 了,以下簡稱為 CXF。CXF 繼承了 Celtix 和 XFire 兩大開源項目的精華,提供了對 JAX-WS 全面的支持,并且提供了多種 Binding 、DataBinding、Transport 以及各種 Format 的支持,并且可以根據(jù)實際項目的需要,采用代碼優(yōu)先(Code First)或者 WSDL 優(yōu)先(WSDL First)來輕松地實現(xiàn) Web Services 的發(fā)布和使用。

支持多種標準

  • 支持 JAX-WS、 JAX-WSA、JSR-181 和 SAAJ;
  • 支持 SOAP 1.1、1.2、WS-I BasicProfile、WS-Security、WS-Addressing、WS-RM 和 WS-Policy;
  • 支持 WSDL 1.1 、2.0;
  • 支持 MTOM;

它支持多種協(xié)議,比如:SOAP1.1,1,2、XML/HTTP、RESTful HTTP 或者 CORBA。CORBA(Common Object Request Broker Architecture公共對象請求代理體系結(jié)構(gòu),早期語言使用的WS。C,c++,C#)

Cxf是基于SOA總線結(jié)構(gòu),依靠spring完成模塊的集成,實現(xiàn)SOA方式。

靈活的部署:可以運行有Tomcat,Jboss,Jetty(內(nèi)置),weblogic上面。

CXF入門案例

我們還以昨天的天氣服務(wù)為案例來看一下CXF的開發(fā)過程。

服務(wù)端的實現(xiàn)

1.創(chuàng)建一個空的java項目,創(chuàng)建一個lib目錄,將所有jar包放入lib目錄
  然后為工程引入jar包,選擇build path,然后Add JARS,只用選擇cxf-manifest.jar即可。

2.創(chuàng)建一個SEI接口,需要在接口上添加@WebService注解

@WebService
public interface WeatherInterface {
    public String queryWeather(String cityName);
}

3.創(chuàng)建SEI接口實現(xiàn)類 

public class WeatherInterfaceImpl implements WeatherInterface {

    public String queryWeather(String cityName) {
        if("河南".equals(cityName)) {
            return "熱爆炸";
        }else {
            return "冰雹";
        }
    }
}

4.發(fā)布服務(wù) 

public class WeatherServer {

    public static void main(String[] args) {
        //創(chuàng)建服務(wù)工廠Bean
        JaxWsServerFactoryBean jaxWsServerFactoryBean=new JaxWsServerFactoryBean();
        //設(shè)置服務(wù)接口
        jaxWsServerFactoryBean.setServiceClass(WeatherInterface.class);
        //設(shè)置服務(wù)實現(xiàn)類
        jaxWsServerFactoryBean.setServiceBean(new WeatherInterfaceImpl());
        //設(shè)置服務(wù)地址
        jaxWsServerFactoryBean.setAddress("http://127.0.0.1:12345/weather");
        //創(chuàng)建服務(wù)
        jaxWsServerFactoryBean.create();
    }

}

5.訪問服務(wù)的wsdl文件地址,看服務(wù)是否發(fā)布成功
    http://127.0.0.1:12345/weather?wsdl

發(fā)布SOAP1.2的服務(wù)端

SOAP分為1.1版本和1.2版本。JDK1.6并不支持1.2,我們可以通過CXF來發(fā)布SOAP1.2的服務(wù)端。
只需要在接口上添加注解 @BindingType(SOAPBinding.SOAP12HTTP_BINDING)。然后重新發(fā)布服務(wù)即可

import javax.jws.WebService;
import javax.xml.ws.BindingType;
import javax.xml.ws.soap.SOAPBinding;

@WebService
@BindingType(SOAPBinding.SOAP12HTTP_BINDING)
public interface WeatherInterface {
    public String queryWeather(String cityName);
}

客戶端的實現(xiàn)

Wsdl2java命令是CXF提供的生成客戶端的工具,他和wsimport類似,可以根據(jù)WSDL生成客戶端代碼 

Wsdl2java常用參數(shù):
-d,指定輸出目錄
-p,指定包名,如果不指定該參數(shù),默認包名是WSDL的命名空間的倒序 

Wsdl2java支持SOAP1.1和SOAP1.2
1.我們先創(chuàng)建一個客戶端項目,然后引入jar包,和上面一樣,使用Add JARS選擇cxf-manifest.jar即可

  然后使用工具生成客戶端

  wsdl2java -p com.cad.cxf -d . http://127.0.0.1:12345/weather?wsdl 

2.創(chuàng)建客戶端 

public class WeatherClient {

    public static void main(String[] args) {
        JaxWsProxyFactoryBean jaxWsProxyFactoryBean=new JaxWsProxyFactoryBean();
        //設(shè)置服務(wù)接口
        jaxWsProxyFactoryBean.setServiceClass(WeatherInterface.class); 
        //設(shè)置服務(wù)地址
        jaxWsProxyFactoryBean.setAddress("http://127.0.0.1:12345/weather");
        //獲取服務(wù)接口實例
        WeatherInterface weatherInterface=(WeatherInterface) jaxWsProxyFactoryBean.create();
        //調(diào)用方法
        String message=weatherInterface.queryWeather("河南");
        System.out.println(message);
    }

}

CXF+Spring整合發(fā)布SOAP模式的服務(wù)

服務(wù)端的實現(xiàn)

1.創(chuàng)建WEB項目,導(dǎo)入jar包 
2.創(chuàng)建SEI接口 

@WebService
@BindingType(SOAPBinding.SOAP12HTTP_BINDING)
public interface WeatherInterface {
    public String queryWeather(String cityName);
}
3.創(chuàng)建SEI實現(xiàn)類 
public class WeatherInterfaceImpl implements WeatherInterface {

    public String queryWeather(String cityName) {
        if("河南".equals(cityName)) {
            return "熱爆炸";
        }else {
            return "冰雹";
        }
    }
}
4.配置spring配置文件,applicationContext.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:jaxrs="http://cxf.apache.org/jaxrs" xmlns:cxf="http://cxf.apache.org/core"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
                            http://www.springframework.org/schema/beans/spring-beans.xsd
                            http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
                            http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
                            http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd">

<!--jaxws:server發(fā)布SOAP協(xié)議的服務(wù) ,對JaxWsServerFactoryBean類封裝-->
<!--serviceClass屬性是服務(wù)接口,address代表地址,因為我們是web服務(wù),不需要輸入ip。serviceBean是服務(wù)實現(xiàn)類-->
<jaxws:server serviceClass="com.cad.cxf.WeatherInterface" address="/weather">
    <jaxws:serviceBean>
        <ref bean="weatherInterfaceImpl"/>
    </jaxws:serviceBean>
</jaxws:server>
<bean name="weatherInterfaceImpl" class="com.cad.cxf.WeatherInterfaceImpl"></bean>
</beans>                            

5.配置web.xml 

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>CXFSpringDemo</display-name>

  //配置Tomcat啟動時加載Spring配置文件 
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:applicationContext.xml</param-value>
  </context-param>
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>

  //配置CXF提供的Servlet
   <servlet>
    <servlet-name>CXF</servlet-name>
    <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>CXF</servlet-name>
    <url-pattern>/ws/*</url-pattern>
  </servlet-mapping>


  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
</web-app>
6.部署到Tomcat下,發(fā)布服務(wù),并訪問 

http://localhost:8080/CXFSpringDemo/ws/weather?wsdl

客戶端的實現(xiàn)

1.創(chuàng)建項目,導(dǎo)入jar包,生成客戶端 

wsdl2java -p com.cad.cxf -d . http://localhost:8080/CXFSpringDemo/ws/weather?wsdl

2.配置Spring文件  

<?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:jaxrs="http://cxf.apache.org/jaxrs" xmlns:cxf="http://cxf.apache.org/core"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
                            http://www.springframework.org/schema/beans/spring-beans.xsd
                            http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
                            http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
                            http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd">
    <!-- <jaxws:client實現(xiàn)客戶端 ,對JaxWsProxyFactoryBean類封裝-->   
    <!-- address是服務(wù)地址,servicelass是服務(wù)接口,返回服務(wù)實現(xiàn)類-->   
    <jaxws:client id="weatherClient" address="http://localhost:8080/CXFSpringDemo/ws/weather" serviceClass="com.cad.cxf.WeatherInterface"/>
</beans>
3.通過Spring容器獲取服務(wù)實現(xiàn)類,調(diào)用方法 

public class WeatherClient {

    public static void main(String[] args) {
        ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
        WeatherInterface  weatherInterface = (WeatherInterface) context.getBean("weatherClient");
        String message=weatherInterface.queryWeather("河南");
        System.out.println(message);
    }

}

CXF發(fā)布REST模式的服務(wù)

REST即表述性狀態(tài)傳遞(英文:Representational State Transfer,簡稱REST),是一種軟件架構(gòu)風(fēng)格。

因為REST模式的Web服務(wù)與復(fù)雜的SOAP和XML-RPC對比來講明顯的更加簡潔,越來越多的web服務(wù)開始采用REST風(fēng)格設(shè)計和實現(xiàn)rest服務(wù)采用HTTP 做傳輸協(xié)議,REST 對于HTTP 的利用實現(xiàn)精確的資源定位。

例如:
非rest方式:http://ip:port/queryUser.action?userType=student&id=001 

Rest方式:http://ip:port/user/student/query/001 
1.創(chuàng)建一個項目,導(dǎo)入CXF jar包 
2.創(chuàng)建一個實體類 Student   
@XmlRootElement(name="student")可以實現(xiàn)XML和對象之間的轉(zhuǎn)換,name屬性指定根元素

@XmlRootElement(name="student")
public class Student {
    private int id;
    private String name;
    private Date birthday;
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public Date getBirthday() {
        return birthday;
    }
    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

}
3.創(chuàng)建SEI接口 

@WebService
//@Path("/student")就是指定訪問該接口的路徑
@Path("/Student")
public interface StudentInterface {
        //指定請求方式,如果服務(wù)端發(fā)布的時候指定的是GET(POST),那么客戶端訪問時必須使用GET(POST
        @GET
        //指定服務(wù)數(shù)據(jù)類型,可以是XML,json等數(shù)據(jù)類型
        @Produces(MediaType.APPLICATION_XML)
        //@Path("/query/{id}")指定該方法的路徑,“{id}”指參數(shù),多個參數(shù),以“/”隔開,放到“{}”中
        @Path("/query/{id}")
        public Student queryStudent(@PathParam("id")int id);

        @GET
        @Produces(MediaType.APPLICATION_XML)
        @Path("/queryList/{name}")
        public List<Student> queryList(@PathParam("name")String name);
}
4.創(chuàng)建SEI實現(xiàn)類 

public class StudentInterfaceImpl implements StudentInterface {
    @Override
    public Student queryStudent(int id) {
        Student s=new Student();
        s.setId(666);
        s.setName("張三");
        s.setBirthday(new Date());
        return s;
    }

    @Override
    public List<Student> queryList(String name) {
        Student s=new Student();
        s.setId(666);
        s.setName("張三");
        s.setBirthday(new Date());

        Student s2=new Student();
        s2.setId(888);
        s2.setName("李四");
        s2.setBirthday(new Date());

        List<Student> l=new ArrayList<Student>();
        l.add(s);
        l.add(s2);
        return l;
    }

}
5.發(fā)布服務(wù) 

public class StudentServer {

    public static void main(String[] args) {
        JAXRSServerFactoryBean jaxrsServerFactoryBean=new JAXRSServerFactoryBean();
        //設(shè)置服務(wù)實現(xiàn)類
        jaxrsServerFactoryBean.setServiceBean(new StudentInterfaceImpl());
        //設(shè)置資源類,如果有多個資源類,可以以“,”隔開,例如Student.class StudentInterface.class都是資源類,但是StudentInterfaceImpl里面已經(jīng)包含了Student.class StudentInterface.class,所以不用重復(fù)指定
        jaxrsServerFactoryBean.setResourceClasses(StudentInterfaceImpl.class); 

        //設(shè)置服務(wù)地址
        jaxrsServerFactoryBean.setAddress("http://127.0.0.1:12345/Class");
        //發(fā)布服務(wù)
        jaxrsServerFactoryBean.create();

    }

}
6.測試服務(wù) 

訪問query方法 
    http://127.0.0.1:12345/Class/Student/query/001

訪問queryList方法 
    http://127.0.0.1:12345/Class/Student/queryList/xxx

如果服務(wù)端發(fā)布時指定請求方式是GET(POST),客戶端必須使用GET(POST)訪問服務(wù)端,否則會報異常。

如果在同一方法上同時指定XML和JSON媒體類型,在GET請求下,默認返回XML,在POST請求下,默認返回JSON

CXF+Spring整合發(fā)布REST模式的服務(wù)

1.創(chuàng)建web項目,引入jar包
2.創(chuàng)建一個實體類 Student   
@XmlRootElement(name="student")可以實現(xiàn)XML和對象之間的轉(zhuǎn)換,name屬性指定根元素

@XmlRootElement(name="student")
public class Student {
    private int id;
    private String name;
    private Date birthday;
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public Date getBirthday() {
        return birthday;
    }
    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

}
3.創(chuàng)建SEI接口 

@WebService
//@Path("/student")就是指定訪問該接口的路徑
@Path("/Student")
public interface StudentInterface {
        //指定請求方式,如果服務(wù)端發(fā)布的時候指定的是GET(POST),那么客戶端訪問時必須使用GET(POST
        @GET
        //指定服務(wù)數(shù)據(jù)類型,可以是XML,json等數(shù)據(jù)類型
        @Produces(MediaType.APPLICATION_XML)
        //@Path("/query/{id}")指定該方法的路徑,“{id}”指參數(shù),多個參數(shù),以“/”隔開,放到“{}”中
        @Path("/query/{id}")
        public Student queryStudent(@PathParam("id")int id);

        @GET
        @Produces(MediaType.APPLICATION_XML)
        @Path("/queryList/{name}")
        public List<Student> queryList(@PathParam("name")String name);
}
4.創(chuàng)建SEI實現(xiàn)類 

public class StudentInterfaceImpl implements StudentInterface {
    @Override
    public Student queryStudent(int id) {
        Student s=new Student();
        s.setId(666);
        s.setName("張三");
        s.setBirthday(new Date());
        return s;
    }

    @Override
    public List<Student> queryList(String name) {
        Student s=new Student();
        s.setId(666);
        s.setName("張三");
        s.setBirthday(new Date());

        Student s2=new Student();
        s2.setId(888);
        s2.setName("李四");
        s2.setBirthday(new Date());

        List<Student> l=new ArrayList<Student>();
        l.add(s);
        l.add(s2);
        return l;
    }

}
第五步:配置Spring配置文件,applicationContext.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:jaxrs="http://cxf.apache.org/jaxrs" xmlns:cxf="http://cxf.apache.org/core"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
                            http://www.springframework.org/schema/beans/spring-beans.xsd
                            http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
                            http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
                            http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd">
    <!-- <jaxrs:server發(fā)布REST的服務(wù) ,對JAXRSServerFactoryBean類封裝-->  
    <jaxrs:server address="/user">
        <jaxrs:serviceBeans>
            <ref bean="studentInterface"/>
        </jaxrs:serviceBeans>
    </jaxrs:server>

    <!-- 配置服務(wù)實現(xiàn)類 -->
    <bean name="studentInterface" class="com.cad.rest.StudentInterfaceImpl"/>
</beans>
6.配置web.xml文件 

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>ws_2_cxf_spring_server</display-name>

  <!-- 設(shè)置spring的環(huán)境 -->
  <context-param>
    <!--contextConfigLocation是不能修改的  -->
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:applicationContext.xml</param-value>
  </context-param>
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>

  <!-- 配置CXF的Servlet -->
  <servlet>
    <servlet-name>CXF</servlet-name>
    <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>CXF</servlet-name>
    <url-pattern>/ws/*</url-pattern>
  </servlet-mapping>

  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
</web-app>
7.部署到Tomcat中,發(fā)布服務(wù),測試一下
http://127.0.0.1:8080/CXFRestDemo/ws/user/Student/query/100

綜合案例:手機歸屬地查詢

1.創(chuàng)建web項目,導(dǎo)入 CXF jar包 
2.生成公網(wǎng)提供的手機歸屬地查詢的客戶端 
wsdl2java -p com.cad.mobile -d . http://ws.webxml.com.cn/WebServices/MobileCodeWS.asmx?wsdl

3.編寫我們自己的SEI接口 

@WebService
public interface MobileInterface {
    public String  queryMobile(String phoneNum);
}
4.編寫我們的SEI實現(xiàn)類 ,里面調(diào)用公網(wǎng)客戶端的查詢方法,我們在Spring配置客戶端,然后注入即可 

public class MobileInterfaceImpl implements MobileInterface {
    //公網(wǎng)客戶端,提供set方法 以便注入
    private MobileCodeWSSoap mobileClient;

    //調(diào)用公網(wǎng)的查詢方法
    public String queryMobile(String phoneNum) {
        return mobileClient.getMobileCodeInfo(phoneNum, "");
    }

    public MobileCodeWSSoap getMobileClient() {
        return mobileClient;
    }

    public void setMobileClient(MobileCodeWSSoap mobileClient) {
        this.mobileClient = mobileClient;
    }


}
5.配置Spring 配置文件 

<?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:jaxrs="http://cxf.apache.org/jaxrs" xmlns:cxf="http://cxf.apache.org/core"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
                            http://www.springframework.org/schema/beans/spring-beans.xsd
                            http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
                            http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
                            http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd">

    <!-- 配置公網(wǎng)客戶端 -->
    <jaxws:client id="mobileClient" address="http://ws.webxml.com.cn/WebServices/MobileCodeWS.asmx" 
        serviceClass="com.cad.mobile.MobileCodeWSSoap"/> 

    <!-- <jaxws:server發(fā)布我們的服務(wù)-->    
    <jaxws:server address="/mobile" serviceClass="com.cad.server.MobileInterface">
        <jaxws:serviceBean>
            <ref bean="mobileServer"/>
        </jaxws:serviceBean>
    </jaxws:server> 

    <!-- 配置我們的服務(wù)實現(xiàn)類 -->
    <bean name="mobileServer" class="com.cad.server.MobileInterfaceImpl">
        <property name="mobileClient" ref="mobileClient"/>
    </bean>     


</beans>        
6.創(chuàng)建查詢頁面 

<body>
    <form action="MobileServlet" method="post">
        手機號歸屬地查詢:<input type="text" name="phoneNum"><input type="submit" value="查詢"><br>
        查詢結(jié)果:${result}
    </form>

</body>
7.創(chuàng)建處理的Servlet

@WebServlet("/MobileServlet")
public class MobileServlet extends HttpServlet {
    private MobileInterface mobileServer;

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //獲取頁面的電話號
        String phoneNum = request.getParameter("phoneNum");
        if(null != phoneNum && !"".equals(phoneNum)){
            //獲取Spring容器
            ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
            //獲取我們的服務(wù)實現(xiàn)類
            mobileServer = (MobileInterface) context.getBean("mobileServer");
            //調(diào)用查詢方法
            String result = mobileServer.queryMobile(phoneNum);
            request.setAttribute("result", result);
        }
        //請求轉(zhuǎn)發(fā)  
        request.getRequestDispatcher("/index.jsp").forward(request, response);

    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        doGet(request, response);
    }

}
8.配置web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
  <display-name>MobileDemo</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>

    <context-param>
    <!--contextConfigLocation是不能修改的  -->
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:applicationContext.xml</param-value>
  </context-param>
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>

  <!-- 配置CXF的Servlet -->
  <servlet>
    <servlet-name>CXF</servlet-name>
    <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>CXF</servlet-name>
    <url-pattern>/ws/*</url-pattern>
  </servlet-mapping>

</web-app>
9.部署Tomcat,訪問測試 

到此這篇關(guān)于Java WebService開源框架CXF詳解的文章就介紹到這了。希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 詳解SpringBoot如何讓指定的Bean先加載

    詳解SpringBoot如何讓指定的Bean先加載

    這篇文章主要給大家介紹了在 SpringBoot 中如何讓自己的某個指定的 Bean 在其他 Bean 前完成被 Spring 加載,文中通過代碼示例給大家講解的非常詳細,對大家的學(xué)習(xí)或工作有一定的幫助,需要的朋友可以參考下
    2024-06-06
  • 一文帶你掌握Spring Security框架的使用

    一文帶你掌握Spring Security框架的使用

    Spring Security是一款基于Spring框架的認證和授權(quán)框架,提供了一系列控制訪問和保護應(yīng)用程序的功能,本文將會對Spring Security框架進行全面詳細的講解,需要的可以參考下
    2023-05-05
  • Java中的同步非阻塞IO模型詳解

    Java中的同步非阻塞IO模型詳解

    這篇文章主要介紹了Java中的同步非阻塞IO模型詳解,同步非阻塞IO模型,我們能夠知道,用戶線程一直發(fā)送請求,內(nèi)核一直都能都夠返回 ,直到內(nèi)核完成準備數(shù)據(jù)、數(shù)據(jù)拷貝的工作,并且返回成功的指示,在此過程中用戶線程不是阻塞的狀態(tài),需要的朋友可以參考下
    2024-01-01
  • Springboot項目打包如何將依賴的jar包輸出到指定目錄

    Springboot項目打包如何將依賴的jar包輸出到指定目錄

    公司要對springboot項目依賴的jar包進行升級,但是遇到一個問題,項目打包之后,沒辦法看到他里面依賴的jar包,版本到底是不是升上去了,沒辦法看到,下面通過本文給大家分享Springboot項目打包如何將依賴的jar包輸出到指定目錄,感興趣的朋友一起看看吧
    2024-05-05
  • Java線性表的順序表示及實現(xiàn)

    Java線性表的順序表示及實現(xiàn)

    這篇文章主要介紹了Java線性表的順序表示及實現(xiàn),順序表是在計算機內(nèi)存中以數(shù)組的形式保存的線性表,線性表的順序存儲是指用一組地址連續(xù)的存儲單元依次存儲線性表中的各個元素、使得線性表中在邏輯結(jié)構(gòu)上相鄰的數(shù)據(jù)元素存儲在相鄰的物理存儲單元中
    2022-07-07
  • java實現(xiàn)微信App支付服務(wù)端

    java實現(xiàn)微信App支付服務(wù)端

    這篇文章主要為大家詳細介紹了java實現(xiàn)微信App支付服務(wù)端,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-10-10
  • Java異常處理try?catch的基本用法

    Java異常處理try?catch的基本用法

    try就像一個網(wǎng),把try{}里面的代碼所拋出的異常都網(wǎng)住,然后把異常交給catch{}里面的代碼去處理。最后執(zhí)行finally之中的代碼。無論try中代碼有沒有異常,也無論catch是否將異常捕獲到,finally中的代碼都一定會被執(zhí)行。
    2021-12-12
  • Java的繪圖模式使用淺析

    Java的繪圖模式使用淺析

    這篇文章主要介紹了Java的繪圖模式使用淺析,以一個小例子大概列舉了XOR模式下能干的一些事情,需要的朋友可以參考下
    2015-10-10
  • java實現(xiàn)微信支付功能

    java實現(xiàn)微信支付功能

    這篇文章主要為大家詳細介紹了java實現(xiàn)微信支付功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-09-09
  • Java遠程共享目錄的操作代碼

    Java遠程共享目錄的操作代碼

    這篇文章主要介紹了java操作遠程共享目錄的實現(xiàn)代碼,非常不粗,具有參考借鑒價值,需要的朋友可以參考下
    2017-08-08

最新評論

二连浩特市| 岚皋县| 棋牌| 冕宁县| 伊宁市| 青冈县| 山丹县| 宁武县| 旌德县| 宁德市| 秭归县| 新干县| 光泽县| 兴安盟| 手游| 屏东县| 呼和浩特市| 醴陵市| 双峰县| 岱山县| 扎鲁特旗| 鄂伦春自治旗| 汝南县| 六安市| 武清区| 两当县| 富裕县| 曲阳县| 儋州市| 抚宁县| 柳江县| 论坛| 惠水县| 黑龙江省| 徐水县| 西畴县| 东方市| 板桥市| 阳信县| 碌曲县| 石狮市|