yishen 发表于 2013-7-11 09:02:41

apache cxf笔记之利用spring创建服务程序

前面我们已经介绍了简单的jax-ws服务程序,关于SEI接口,接口的实现还有服务的发布。这边将介绍另外一种服务的发布形式——基于spring容器。其中SEI接口和接口实现类代码不改变,参见上一次的apachecxf笔记。在原有的项目的src目录先创建server-beans.xml文件:
<?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"
    xsi:schemaLocation="http://www.springframework.org/schema/beans   
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://cxf.apache.org/jaxws
    http://cxf.apache.org/schemas/jaxws.xsd">
      
    <jaxws:endpoint
      id="ProjectManager" implementor="demo.cxf.helloworld.HelloWorldImpl"   
      address="http://localhost:8080/HelloWorld"/>

</beans>
编写测试代码:
SpringServer类:
package demo.cxf.helloworld.server;

import java.io.IOException;

import org.springframework.context.support.ClassPathXmlApplicationContext;

public class SpringServer {

    public static void main(String[] args) throws IOException {
      SpringServer springServer = new SpringServer();
      springServer.startServer();
      System.out.println("Startting ready...");
      System.in.read();//按任意键退出
      System.out.println("Server exiting...");
      System.exit(0);//程序退出
    }
      
    public void startServer(){
      System.out.println("Starting Server.....");
         
      //通过spring容器读取服务配置信息,创建服务
      new ClassPathXmlApplicationContext(new String[]{"classpath:server-beans.xml"});
    }
}
运行,控制台为:

浏览器访问:http://localhost:8080/HelloWorld?wsdl

123sw 发表于 2013-7-11 15:08:07

有道理。。。

sol229 发表于 2013-7-11 21:09:11

所有的男人生来平等,结婚的除外。

cjcmay 发表于 2013-7-12 19:16:31

穿别人的鞋,走自己的路,让他们找去吧。

赤色烙印 发表于 2013-7-13 00:56:27

美女未抱身先走,常使色狼泪满襟。。。。。。

cixiren 发表于 2013-7-13 08:55:14

男人靠的住,母猪能上树!

359025439 发表于 2013-7-14 05:37:39

我妈常说,我们家要是没有电话就不会这么穷。
页: [1]
查看完整版本: apache cxf笔记之利用spring创建服务程序