惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

H
Help Net Security
博客园 - Franky
GbyAI
GbyAI
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
爱范儿
爱范儿
IT之家
IT之家
酷 壳 – CoolShell
酷 壳 – CoolShell
aimingoo的专栏
aimingoo的专栏
博客园_首页
MongoDB | Blog
MongoDB | Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Recent Announcements
Recent Announcements
Scott Helme
Scott Helme
有赞技术团队
有赞技术团队
M
MIT News - Artificial intelligence
C
CERT Recently Published Vulnerability Notes
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Jina AI
Jina AI
F
Fortinet All Blogs
N
Netflix TechBlog - Medium
L
LangChain Blog
L
LINUX DO - 最新话题
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
H
Hacker News: Front Page
MyScale Blog
MyScale Blog
P
Palo Alto Networks Blog
G
Google Developers Blog
Google DeepMind News
Google DeepMind News
AI
AI
T
Troy Hunt's Blog
Microsoft Azure Blog
Microsoft Azure Blog
阮一峰的网络日志
阮一峰的网络日志
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Vercel News
Vercel News
Microsoft Security Blog
Microsoft Security Blog
罗磊的独立博客
S
Secure Thoughts
大猫的无限游戏
大猫的无限游戏
博客园 - 叶小钗
人人都是产品经理
人人都是产品经理
Blog — PlanetScale
Blog — PlanetScale
博客园 - 司徒正美
Apple Machine Learning Research
Apple Machine Learning Research
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 三生石上(FineUI控件)
S
Security @ Cisco Blogs
Cloudbric
Cloudbric
E
Exploit-DB.com RSS Feed
Attack and Defense Labs
Attack and Defense Labs

博客园 - 电视机9号

转业 SQL SERVER 连接数查看 spring2.5+junit4.4单元测试备忘 Bug Yang,不容易啊! 烦啊~~~ 《疯狂的程序员64》读后感 redmine配置运行备忘录 把爱情给了程序(转帖) 已经下订单了——08博客园T恤 java直接连接Access数据库 ASsql中文问题 新电脑,果然厉害 这地震,也太不靠谱了 准备,ready for ~~~~ 真的要休息了 Flex数据服务——延时加载研究报告 寻找机遇 转转口味 2007年度总结
CXF使用备忘
电视机9号 · 2008-06-30 · via 博客园 - 电视机9号

在javaeye里参考大牛们的帖子去配置spring2.5+hibernate3.2+CXF2.1,最终解决了路径问题后,终于成功了!
CXF是Apache的一个重点项目,终于放出来了,因为它跟spring的结合很方便,于是就用一下,还是要自己动手一步步弄一下,才知道其配置上的一些小细节(如果用插件的话,就感觉不到它跟spring的关系和不知道它的很多细节,所以推荐不要用插件的好)。
在这里顺带提一下,spring2.5结合junit4.4可以很容易地运用annotation来进行testcase的编写,不过要注意的是eclipse3.3或者eclipose3.4,里头自带的junit4是junit4.3版本的,缺少需要的方法,所以要去下载最新的junit4.4版,然后替换掉eclipse插件里的junit.jar包。

  1. 准备依赖包,依赖包不用想那么多,我在这里是把握的项目包弄个截图,所以是很多的,重点是spring,hibernate,CXF*这些包。

  2. 在web.xml文件中添加以下servlet配置:

    <!-- CXF 配置 -->
        
    <servlet>
            
    <servlet-name>CXFServlet</servlet-name>
            
    <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
            
    <load-on-startup>1</load-on-startup>
        
    </servlet>
        
    <servlet-mapping>
            
    <servlet-name>CXFServlet</servlet-name>
            
    <url-pattern>/services/*</url-pattern>
        
    </servlet-mapping>


  3. 添加applicationContext-cxf.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://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd http://www.springframework.org/schema/beans  http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"
        default-autowire
    ="byName" default-lazy-init="true">
        
    <description>基于Apache CXF的Web Service配置文件</description>
        
        
    <import resource="classpath:META-INF/cxf/cxf.xml"/>
        
    <import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>
        
    <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml"/>
        
    <import
            
    resource="classpath:META-INF/cxf/cxf-extension-javascript-client.xml"/>
        
        
    <bean id="helloWorldImpl" class="com.lbg.ws.test.impl.HelloWorld"/>
        
        
    <jaxws:endpoint id="helloWorld" implementor="#helloWorldImpl"
            address
    ="/HelloWorld"/>
    </beans>


  4. 建立webservice的接口与实现:

    package com.lbg.ws.test;

    import javax.jws.WebMethod;
    import javax.jws.WebService;

    @WebService(name
    ="HelloWorld")
    public interface IHelloWorld {

        @WebMethod(operationName
    ="sayHello")
        
    public String sayHello();
    }

    package com.lbg.ws.test.impl;

    import javax.jws.WebService;

    import com.lbg.ws.test.IHelloWorld;

    @WebService(endpointInterface
    ="com.lbg.ws.test.IHelloWorld")
    public class HelloWorld implements IHelloWorld {

        
    public String sayHello() {
            
    return "HelloWorld!";
        }

    }

  5. 把项目部署到tomcat或其它j2ee容器上启动,成功信息如下:

    2008-6-30 21:16:57 org.apache.cxf.service.factory.ReflectionServiceFactoryBean buildServiceFromClass
    信息: Creating Service {http://impl.test.ws.lbg.com/}HelloWorldService from class com.lbg.ws.test.IHelloWorld
    2008-6-30 21:16:57 org.apache.cxf.endpoint.ServerImpl initDestination
    信息: Setting the server's publish address to be /HelloWorld
    好了,那么样才能够看到wsdl文档呢?关键就在web.xml配置servlet那里,

    <
    servlet-mapping>
            
    <servlet-name>CXFServlet</servlet-name>
            
    <url-pattern>/services/*</url-pattern>
    </servlet-mapping>

这个mapping里的<url-pattern>就是你的所有webservice的访问路径了,而在applicationContext-cxf.xml中定义的服务RUL是"/HelloWorld",你的应用服务是这样:http://localhost:8080/testProject/,那么上面的webservice访问路径就是http://localhost:8080/testProject/services/HelloWorld?wsdl。