I. Overview
We can add a Web Service layer based on traditional Java EE applications, so that our Java EE applications can leak Web services externally, in this way, the Java EE application can be called by any platform or program written in any language.
2. Steps
<喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + CjEuINDCvah3ZWK5pLPMc3ByaW5nQ1hGLCCyori01sbQ6NKqtcRKYXKw/fill = "brush: java;"> ContextConfigLocation /WEB-INF/config/applicationContext. xml Org. springframework. web. context. ContextLoaderListener CXFServlet Org. apache. cxf. transport. servlet. CXFServlet CXFServlet /WebService /*
3. Import the Schema and xml configuration file provided by CXF in the Spring configuration file applicationContext. xml, and use the jaxws: endpoint element to expose the web service.
4. interfaces and implementation classes:
HelloService
// Annotation with @ WebService Annotation, indicating that this interface will correspond to a Web Services @ WebServicepublic interface HelloService {// define a method, this method will be exposed as a Web Services Operation public void sayHello (String name );}
HelloServiceImpl
@WebService(endpointInterface = "com.zdp.service.HelloService")public class HelloServiceImpl implements HelloService{ public void sayHello(String name) {System.out.println("hello " + name + ", current time is " + new Date());}}
5. Start the tomcat server
6. Create a Java project cxf_Client and enter the src directory of the project on the command line.
Run the following command: wsdl2java http: // localhost: 9999/springCXF/webService/sayHello? Wsdl
7. Write a test class:
Public class MyClient {public static void main (String [] args) {HelloServiceImplService factory = new HelloServiceImplService (); HelloService helloService = factory. getHelloServiceImplPort (); // return a proxy helloService. sayHello ("zhangsan ");}}
3. Configure the interceptor
In fact, the configuration interceptor is to add a configuration in applicationContext. xml, the specific interceptor class see the previous blog: http://blog.csdn.net/zdp072/article/details/29245575