java web通过cxf发布webservices,Tomcat上通过CXF实现不用注解发布WebService

Tomcat下通过CXF实现不用注解发布WebService

最近开始学习CXF框架下部署WebServices  , 起初都是用注释类或使用JAX-WS的方式如@WebService 等方式来进行和Spring结合发布的WebService

但是后来突然发现这样无形中和Java代码的耦合程度更大了,于是便需找累死xfie的aegis方式进行部署,貌似这类的文章很难找,

虽然找了大概三四天吧不过很幸运,感谢博主http://blog.csdn.net/pengchua/article/details/2740588

本文将通过图文方式进行部署,顺便把和Spring的结合进行讲解一下:

1....................首先看一下我的工程目录,这样会更容易下面的理解

151457247.gif

2...............................配置web.xml文件这样所有架构才能启动(之前别忘记加入Spring和CXF的架包)

xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"

xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"

id="WebApp_ID" version="2.5">

contextConfigLocation

classpath:applicationContext-server.xml

org.springframework.web.context.ContextLoaderListener

CXFServlet

org.apache.cxf.transport.servlet.CXFServlet

1

CXFServlet

/services/*

index.jsp

3.....................................Spring 配置文件applicationContext.xml的配置

xmlns:context="http://www.springframework.org/schema/context"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans-3.0.xsd

http://www.springframework.org/schema/context

http://www.springframework.org/schema/context/spring-context-3.0.xsd">

4................................编写接口文件

package com.interfaces;

import java.util.List;

import java.util.Map;

import org.w3c.dom.Document;

import com.javabean.User;

public interface ServicesInterface {

//字符串

public String sayHi(String text);

//document类型对象

public Document getDocument();

String sayUserHello(User user);

List findUsers();

Map getMapUsers();

}

5...................编写实现类(这些应该都是小儿科了吧)

package com.interfaces;

import java.util.List;

import java.util.Map;

import org.w3c.dom.Document;

import com.javabean.User;

public interface ServicesInterface {

//字符串

public String sayHi(String text);

//document类型对象

public Document getDocument();

String sayUserHello(User user);

List findUsers();

Map getMapUsers();

}

6........................看看User这个JavaBean里面有什么冬冬

package com.javabean;

public class User {

private String username;

private String password;

public String getUsername() {

return username;

}

public void setUsername(String username) {

this.username = username;

}

public String getPassword() {

return password;

}

public void setPassword(String password) {

this.password = password;

}

}

7........................配置services.xml就是用来部署接口的这个文件,这个很重要,真的很重要(后面就知道为什么了)

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:simple="http://cxf.apache.org/simple"

xmlns:soap="http://cxf.apache.org/bindings/soap"

xsi:schemaLocation="

http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd

http://cxf.apache.org/core

http://cxf.apache.org/schemas/core.xsd

http://cxf.apache.org/simple

http://cxf.apache.org/schemas/simple.xsd">

address="/hello">

注意:上面的配置文件中不仅要注意配置的内容,而且要注意配置的顺序,例如

http://cxf.apache.org/simple

http://cxf.apache.org/schemas/simple.xsd

这两个的先后顺序是不能颠倒的,唉,在这里吃好大亏啊,如果颠倒了的话在写下面的标签的时候你回发现根本找不到simple的标签,所以一定要注意

8.............................如果一切顺利的话那么就来启动服务器来看看我们的成果吧

http://localhost:8080/aegis_CXF/services/hello?wsdl

呵呵最喜欢看到下面这张图了

151457248.gif

9......................给自己点鼓励(恭喜恭喜呵呵)

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值