Web-based cxf first release method-simple release

Source: Internet
Author: User

The cxf release method described above is only available to javase. The following is the first release method for web-based cxf-simple release.


1. Import package

Create a new webproject and import the basic jar package of cxf (67 in total)

2. Web. xml

Add the following code to Web. xml:

<! -- Configure the core servlet of cxf --> <servlet-Name> cxf </servlet-Name> <! -- If the name is too long to remember, you can create a class and inherit the class name --> <servlet-class> Org. apache. cxf. transport. servlet. cxfservlet </servlet-class> </servlet> <servlet-mapping> <servlet-Name> cxf </servlet-Name> <URL-pattern>/cxf/* </URL -Pattern> </servlet-mapping>

3. helloservice

Package COM. njupt. cxf; import Java. text. simpledateformat; import Java. util. date; import javax. JWS. webService; import javax. XML. WS. bindingtype; import javax. XML. WS. soap. soapbinding; @ WebService // if it is not added, the method @ bindingtype (value = soapbinding. soap12http_binding) // change soap1.1 protocol to soap1.2 protocol public class helloservice {Public String sayhello (string name) {simpledateformat SDF = new simpledateformat ("yyyy/mm/dd hh: mm: SS "); Return SDF. format (new date () + "hello" + name ;}}

4. cxf-servlet.xml

Create a file named cxf-servlet.xml under Web-INF with the following code:

<? 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-3.0.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 "> <! -- The introduction of cxf bean definition is as follows, used in earlier versions --> <import resource = "classpath: META-INF/cxf. XML "/> <import resource =" classpath: META-INF/cxf/cxf-extension-soap.xml "/> <import resource =" classpath: META-INF/cxf/cxf-servlet.xml "/> <! -- First release method: simple release (release without Interface) --> <! -- ID: the unique identifier implementor: The Class address that provides the service: the request URL of the Service --> <jaxws: endpoint id = "helloservice" implementor = "com. njupt. cxf. helloservice "address ="/Hello "> <! -- Add the request message interceptor --> <jaxws: ininterceptors> <! -- If the name is too long to remember, you can create a new class and find the full name of the class in the inherited way --> <Bean class = "org. apache. cxf. interceptor. loggingininterceptor "> </bean> </jaxws: ininterceptors> <! -- Add the Response Message interceptor --> <jaxws: outinterceptors> <Bean class = "org. apache. cxf. interceptor. loggingoutinterceptor "> </bean> </jaxws: outinterceptors> </jaxws: endpoint> </beans>

5. Deploy the project to Tomcat

6. In the address bar, enter http: // localhost: 8080/cxf_3/cxf/Hello? Perform a test on WSDL. (If you cannot remember it, enter http: // localhost: 8080/cxf_3/cxf and follow the prompts to proceed step by step)


7. For more information, see the preceding call method.

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.