Use CXF to write a simple instance of a Web service

Source: Internet
Author: User

Increase CXF Dependency

<dependency>        <groupId>org.apache.cxf</groupId>        <artifactid>apache-cxf</ artifactid>        <version>${cxf.version}</version>        <type>pom</type>  </ Dependency>

Creating a Service Interface

import Javax.jws.WebService; @WebService Public InterfaceHelloWorld { Publicstring Sayhi (string text);} Import Javax.jws.WebService; @WebService Public classHellowwordcontroller implements HelloWorld {/** (Non-javadoc) * * @see Com.wfj.infc.helloworld#sayhi (java.lang.String)*/     Publicstring Sayhi (string text) {//TODO auto-generated Method StubSystem. out. println ("Sayhi called"); return "Hello"+text; }}

Cxfdemo-beans.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"xsi:schemalocation="Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http//Cxf.apache.org/jaxwshttp://cxf.apache.org/schemas/jaxws.xsd"       default-autowire="byname"> <import resource="Classpath:meta-inf/cxf/cxf.xml"/> <import resource="Classpath:meta-inf/cxf/cxf-servlet.xml"/> <bean id="Hello" class="Com.wangfj.product.core.controller.HellowWordController"/> <jaxws:endpoint id="HelloWorld"Implementor="#hello"address="/WEBSERVICE/HW"/></beans>
Published in WebApp

The XF provides the integration of spring and also provides the org.apache.cxf.transport.servlet.CXFServlet for publishing webservice in the Web container. The previous example adds an entire APACHE-CXF dependency, so the reference to Srping is added automatically. Just write the beans configuration file and the Web. xml file.

    • Configuring Cxfservlet in Web. xml
<servlet>        <servlet-name>CXFServlet</servlet-name>        <servlet-class> org.apache.cxf.transport.servlet.cxfservlet</servlet-class>    </servlet>    < servlet-mapping>        <servlet-name>CXFServlet</servlet-name>        <url-pattern>/services /* </url-pattern>    </servlet-mapping>
<context-param>         <param-name>contextConfigLocation</param-name>        <param-value>/ web-inf/cxfdemo-beans.xml</param-value>    </context-param>    <listener>        < listener-class>org.springframework.web.context.contextloaderlistener</listener-class >    </listener>

Use CXF to write a simple instance of a Web service

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.