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



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Mr-稻帅

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值