CXF is a webservice frame, similar to axis, the following is the basic use of CXF.
The first thing to do is to download the Cxf file, and then to introduce the jar package into the project, which can be managed by MAVEN, of course. I'm using the latest version of 3.2.1, jar pack a lot, not very clear, a brain of all introduced.
Service side
Then write the service-side code, the structure of my server is as follows:
Standardtime is an entity object, the return value of my method, a custom standardtime is used to describe the object that can be returned with CXF, or it can return a collection type, a base type, a string, and so on.
Then there is the interface and implementation class, and finally WSServer is used to start webservice.
The interface and implementation classes are as follows:
The entity class and startup class are as follows
The startup class adds a log-out interceptor that can be used to print information returned to the client.
Client
Unlike the framework that comes with the JDK, the code that generates the client uses the Wsdl2java tool, and the detailed use of the Wsdl2java, please Baidu itself.
Create a new client project, build a package such as cxf.base.client, into the project SRC directory, in the address bar input cmd and enter, will open a command line window, directory is src directory, execute the following command:
Wsdl2java-p cxf.base.client-client http://192.168.0.102:9999/synctimews?wsdl
The client code is generated, as follows:
Then you can test it, and the test class is as follows:
A log-out interceptor is also used to print out the information sent by the client, which returns a custom object.
The results of the test are as follows:
Webserive Learning Record 2-CXF Framework Foundation use