Step by Step Create cxf+spring webservice based on Maven

Step by Step

develop WSDL-First Simple Request-Response Webservice

based on CXF+SPRING+MAVEN

(图片太多,稍后再传)

一、创建一个简单的基于cxf+springmaven project

a)         Create a Maven Project  

 

b)         Select an simple Cxf-spring archetype(cxf-http-basic): include snapshot archetypes

 

c)         Specify Archetype parameters

 

完成后,maven就开始构建project了。如果没有设置你自己的maven local repository,那需要download plugin jar一段时间

d)         一个以groupId为名称的project生成了:

 

e)         有些包的错误,由于maven自动生成了一个helloWorldwebservice而有些路径错误导致,直接删掉有错误的java类,这些都不是我们需要的

 

二、修改POM 文件

1.         Add properties:

                                                                   i.             

2.         Add dependencies:

 

三、添加,修改wsdl

a)        

b)         Add yours wsdl,define wsdl namespace(targetNamespace [distinguish with other wsdl file]and xmlns:tns[used for current file])

c)        

d)         Add Types

就是些对象(这些对象可以在后面当做接口的输入输出参数,也可当做错误信息对象)便于jxb自动生成java

 

e)         Add xsd file to define your types(也可以定义在wsdl文件中)

 

 

 

Modify your xsd to follow a sensible style:

 

Define your BO and exception Object:

 

 

f)           

四、添加,修改jxb binding.xml

a)         Add jaxb ‘bindings.xml’ to bind your xsd file, jxb will automatically generate POJOs:

 

Modify binding configuration(define xsd location and pojo package name):

 

b)         Import your xsd into your types:

 

c)         Define your messages, which is your input and output info referring to your types as well as fault info(Do not forget import your xsd namespace into your wsdl head)

 

 

d)         Input

 

e)         Output:

 

f)          Exception handling object

 

g)         Next, define your interface in portType:

 

h)         Define your method intended to be invoked, Each operation is just the method to be deployed publicly:

 

                                                     i.              Define your methodName

 

                                                   ii.              add input, output and fault object  defined above related to the method

 

                                                  iii.              Continue, bind your service (refer to the interface defined above) to a protocol u choose in ‘<binding/>’:

 

                                                  iv.              Add binding service method as well as encoding style of the transport message:

 

i)           Last define your service with binding protocol referred above facilitating transporting messages

 

j)           Whole wsdl:

k)         Then, continue to define into POM file:

                                                     i.              Define execution to run wsdl2java goal:

 

l)           Add jetty plugin:

m)      

n)         Run maven generate-source

 

o)         Run mvn clean install

p)         Run mvn install eclipse:eclipse or click “Update Project Configuration”,alternatively, u want to add new auto-generated file into buildpath manually

 

五、实现web service

a)         After that, Implement your serviceImpl to auto-generated Server interface

 

b)         Add your business logic

 

c)          

六、注册endpoint

Finally, Register endpoint to spring bean context:

Beans.xml:对于不熟悉spring的,短期完成作业可就学习IOC的部分即可(个人建议,仅供参考)

Define your implement class here and address (webapp root path):

 

 

七、Run and deploy web service

 

Run: mvn jetty:run

 

deploy web service successfully!!

 

 

八、SOUPUI测试web service

Test your webservice via SOUPUI:

1.       New soapUI Project

a)        

b)         Add wsdl:

c)        

d)        

e)         Now You can test:

f)         

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值