欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Java?WebService開源框架CXF詳解

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

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入門案例

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

服務端的實現(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ā)布服務 

public class WeatherServer {

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

}

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

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

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

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();
        //設置服務接口
        jaxWsProxyFactoryBean.setServiceClass(WeatherInterface.class); 
        //設置服務地址
        jaxWsProxyFactoryBean.setAddress("http://127.0.0.1:12345/weather");
        //獲取服務接口實例
        WeatherInterface weatherInterface=(WeatherInterface) jaxWsProxyFactoryBean.create();
        //調(diào)用方法
        String message=weatherInterface.queryWeather("河南");
        System.out.println(message);
    }

}

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

服務端的實現(xiàn)

1.創(chuàng)建WEB項目,導入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é)議的服務 ,對JaxWsServerFactoryBean類封裝-->
<!--serviceClass屬性是服務接口,address代表地址,因為我們是web服務,不需要輸入ip。serviceBean是服務實現(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ā)布服務,并訪問 

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

客戶端的實現(xiàn)

1.創(chuàng)建項目,導入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是服務地址,servicelass是服務接口,返回服務實現(xiàn)類-->   
    <jaxws:client id="weatherClient" address="http://localhost:8080/CXFSpringDemo/ws/weather" serviceClass="com.cad.cxf.WeatherInterface"/>
</beans>
3.通過Spring容器獲取服務實現(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模式的服務

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

因為REST模式的Web服務與復雜的SOAP和XML-RPC對比來講明顯的更加簡潔,越來越多的web服務開始采用REST風格設計和實現(xiàn)rest服務采用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)建一個項目,導入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 {
        //指定請求方式,如果服務端發(fā)布的時候指定的是GET(POST),那么客戶端訪問時必須使用GET(POST
        @GET
        //指定服務數(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ā)布服務 

public class StudentServer {

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

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

    }

}
6.測試服務 

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

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

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

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

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

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 {
        //指定請求方式,如果服務端發(fā)布的時候指定的是GET(POST),那么客戶端訪問時必須使用GET(POST
        @GET
        //指定服務數(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的服務 ,對JAXRSServerFactoryBean類封裝-->  
    <jaxrs:server address="/user">
        <jaxrs:serviceBeans>
            <ref bean="studentInterface"/>
        </jaxrs:serviceBeans>
    </jaxrs:server>

    <!-- 配置服務實現(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>

  <!-- 設置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ā)布服務,測試一下
http://127.0.0.1:8080/CXFRestDemo/ws/user/Student/query/100

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

1.創(chuàng)建web項目,導入 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ā)布我們的服務-->    
    <jaxws:server address="/mobile" serviceClass="com.cad.server.MobileInterface">
        <jaxws:serviceBean>
            <ref bean="mobileServer"/>
        </jaxws:serviceBean>
    </jaxws:server> 

    <!-- 配置我們的服務實現(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());
            //獲取我們的服務實現(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詳解的文章就介紹到這了。希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • spring cloud整合ribbon問題及解決方案

    spring cloud整合ribbon問題及解決方案

    很多小伙伴在整合ribbon都出了相同的問題,今天特地為大家整理了該問題的解決方案,文中有非常詳細的圖文解說,對出現(xiàn)同樣問題的小伙伴們很有幫助,需要的朋友可以參考下
    2021-05-05
  • Mybatis常見注解有哪些(總結(jié))

    Mybatis常見注解有哪些(總結(jié))

    這篇文章主要介紹了Mybatis常見注解有哪些(總結(jié)),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2021-03-03
  • 巧妙mybatis避免Where 空條件的尷尬

    巧妙mybatis避免Where 空條件的尷尬

    這篇文章主要介紹了巧妙mybatis避免Where 空條件的尷尬,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-11-11
  • IDEA基于支付寶小程序搭建springboot項目的詳細步驟

    IDEA基于支付寶小程序搭建springboot項目的詳細步驟

    這篇文章主要介紹了IDEA基于支付寶小程序搭建springboot項目的詳細步驟,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2019-04-04
  • 淺談Java回收對象的標記和對象的二次標記過程

    淺談Java回收對象的標記和對象的二次標記過程

    這篇文章主要介紹了淺談Java回收對象的標記和對象的二次標記過程的相關(guān)內(nèi)容,小編覺得還是挺不錯的,這里給大家分享一下,需要的朋友可以參考。
    2017-10-10
  • springboot2如何集成ElasticSearch6.4.3

    springboot2如何集成ElasticSearch6.4.3

    這篇文章主要介紹了springboot2如何集成ElasticSearch6.4.3問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-07-07
  • java文件的簡單讀寫操作方法實例分析

    java文件的簡單讀寫操作方法實例分析

    這篇文章主要介紹了java文件的簡單讀寫操作方法,結(jié)合實例形式分析了java文件流進行讀寫操作的方法與相關(guān)操作注意事項,需要的朋友可以參考下
    2020-05-05
  • Spring中的八大模式簡單介紹

    Spring中的八大模式簡單介紹

    這篇文章主要介紹了Spring中的八大模式簡單介紹,結(jié)合實例代碼給大家講解的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2023-06-06
  • 詳解Spring-Cloud2.0之Feign調(diào)用遠程服務指南

    詳解Spring-Cloud2.0之Feign調(diào)用遠程服務指南

    這篇文章主要介紹了詳解Spring-Cloud2.0之Feign調(diào)用遠程服務指南,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2019-01-01
  • packages思維及使用Java添加Android平臺特定實現(xiàn)

    packages思維及使用Java添加Android平臺特定實現(xiàn)

    這篇文章主要為大家介紹了packages思維及使用Java添加Android平臺特定實現(xiàn)在Flutter框架里的體現(xiàn)和運用詳解,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-12-12

最新評論