Use CXF + spring to create a web interface project

Source: Internet
Author: User

I. web project Integration spring

1.1 open Myeclipse, create a web project (eclipse is a dynamic web project), and use J2EE5.0.

1.2 Add the basic jar package for Srping (no transactions required)

Org. springframework. beans-3.1.1.RELEASE.jar

commons-logging.jarorg.springframework.aop-3.1.1.RELEASE.jarorg.springframework.asm-3.1.1.RELEASE.jarorg.springframework.beans-3.1.1.RELEASE.jarorg.springframework.context-3.1.1.RELEASE.jarorg.springframework.context.support-3.1.1.RELEASE.jarorg.springframework.core-3.1.1.RELEASE.jarorg.springframework.expression-3.1.1.RELEASE.jarorg.springframework.orm-3.1.1.RELEASE.jarorg.springframework.web-3.1.1.RELEASE.jar

1.3 add source folder conf under the project and add applicationContext. xml to the directory. The content is as follows:

 
 

1.4 Add a listener under the web-app node in web. xml as follows:

 
  
   contextConfigLocation
  
  
   classpath:applicationContext.xml
  
 
 
  
   org.springframework.web.context.ContextLoaderListener
  
 

Run the project.

2. Develop webservice

Create a RegeditService class as follows:

Package zxn. ws. service; import javax. jws. webParam; import javax. jws. webService; @ WebServicepublic interface RegeditService {/*** Registration Method * @ param username * @ param password * @ return */public String regedit (@ WebParam (name = "username ") string username, @ WebParam (name = "password") String password );}
Create the RegeditServiceImpl class as follows:
Package zxn. ws. service; import javax. jws. webService; @ WebService (endpointInterface = "zxn. ws. service. regeditService ", serviceName =" Regedit ", targetNamespace =" http://service.ws.zxn /") public class RegeditServiceImpl implements RegeditService {/*** Registration Method * @ param username * @ param password * @ return */public String regedit (String username, String password) {return username + ", you have successfully registered! ";}}

Note: Write the package name in targetNamespace backwards and add "/" to the end; otherwise, an error is returned.

Iii. Integrate cxf with spring

3.1 Add a jar package

cxf-2.7.8.jarneethi-3.0.2.jarxmlschema-core-2.0.3.jarwsdl4j-1.6.3.jarasm-3.3.jar
3.2 Add the following content to applicationContext. xml:

    
     
     
 
 
3.3 Add the following cxf configuration in web. xml:

    
 
           
  
   CXFServlet
           
  
                   org.apache.cxf.transport.servlet.CXFServlet         
           
  
   1
       
      
 
           
  
   CXFServlet
          
  
   /services/*
       
 

Deploy the service to tomcat. The access address is http: // localhost: 8080/CXFWS/services (the last service is the access path configured in 3.3). If so, the service is successful:

The wsdl document is as follows:


Additional source code address: http://download.csdn.net/detail/zxnlmj/7457693

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.