Developed using CXF WebService server side notes _

Developed using CXF WebService server side notes _

1, to achieve the functions:

To achieve the functionality is very simple server-side to provide a user password under the login name check services, as a String type of input parameters, the return value is String type, is indeed very simple, simply could not be more simple.

What is not here to explain the meaning of CXF, CXF Why should these academic problems, do not know the answer of their own to baidu and google to find out.

2, implementation steps:

Our web project from an empty to begin with, step by step shows how to perform and verify.

2.0 Preparing Files:

Download the release CXF file, download the address is, I downloaded the latest version is 2.2.7, unzipped directly into the apache-cxf-2.2.7/lib, the jar file in the directory stored separately and will be imported into the web project. A total of 66 files more then 26MB.

New web 2.1 project webproject, into the jar cxf file, and then modify the web.xml file:


<param-name> contextConfigLocation </ param-name>

<param-value> classpath *: application *. xml </ param-value>

</ Context-param>




</ Listener-class>

</ Listener>

<! - The first two on Needless to say, here is our concern CXF configuration ->


<servlet-name> CXFServlet </ servlet-name>



</ Servlet-class>

<load-on-startup> 1 </ load-on-startup>

</ Servlet>


<servlet-name> CXFServlet </ servlet-name>

<url-pattern> / services / * </ url-pattern>

</ Servlet-mapping>

This is only the prelude, the following steps of writing into the service.

2.2 write server-side services and configuration CXF

Service interface file code is as follows:

package com.demo.service.userinfo;

import javax.jws.WebService;

@ WebService / / WebService annotation using jws

/ / If not the label, can not be published as web services, and know not?

public interface IUserService (

public String getPassword (String loginName);


Service implementation class file code is as follows

package com.demo.service.userinfo.impl;

import javax.jws.WebService;

import com.demo.service.userinfo.IUserService;

@ WebService / / WebService annotation using jws

/ / If not the label, can not be published as web services, and know not?

public class UserServiceImpl implements IUserService (

@ Override

public String getPassword (String loginName) (

System.out.println ("Server's getPassord () is called:" + loginName);

return loginName + "'s password = 123456";

/ / This is the demo program, so casually written, formal development and the right to remove debugging information



CXF configuration: configure a file in src applicationContext_cxf.xml, which reads as follows:

<Beans xmlns = ""

xmlns: xsi = ""

xmlns: jaxws = ""

xmlns: soap = ""

xsi: schemaLocation = " ">

<import resource="classpath:META-INF/cxf/cxf.xml" />

<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />

<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />

<! - This configuration of three lines do not have to check whether the path corresponds to the corresponding file will be automatically generated for cxf ->


<!-UserInfoService do not have to explain that this is a typical Spring configuration, development, suggested by Spring2.5 annotation ->

<Jaxws: endpoint

/ / This should be configured as a client to use to do it, note that I use the web to identify it

implementor = "# userService" / / This is the quote above userService

address = "/ callUserService">

/ / This is the web address of the service call, know why I call the right to use, easy to understand, right?

</ Jaxws: endpoint>

</ Beans>

Note in the above program I write does not increase so much, no time to add the first, second and superfluous, it is proposed ctrl + c and ctrl + v to a certain number of students to pay attention to the matter, do not say my program has problem.

It now has a problem: configured so long, how do not see the wsdl document? No wsdl file, how do you know did the right thing ah? According to the above configuration, visit the URL wsdl how much ah? Guess what?

Wsdl the URL can be absurd to access the value of it? (IP address and port number to change based on actual needs its own) If not, you should carefully reflect on friends. Well, we look at the content of our userService the wsdl. See attachment picture.

Server-side steps that done? What do you think about it, right? No, worse last step is to code the client needs into a jar file guide, to return to the client for debugging. Then we complete this final step it.

At the same time with the mouse to select com.demo.service.userinfo and com.demo.service.userinfo, then: Right - "Export .... -" Java -> Jar file - "select save path and file name, save me as "ws.userinfo.jar".

分类:Java 时间:2010-03-26 人气:538
blog comments powered by Disqus


iOS 开发

Android 开发

Python 开发



PHP 开发

Ruby 开发






Javascript 开发

.NET 开发



Copyright (C), All Rights Reserved. 版权所有 闽ICP备15018612号

processed in 0.034 (s). 13 q(s)