教学文库网 - 权威文档分享云平台
您的当前位置:首页 > 精品文档 > 互联网资料 >

WebService CXF学习(8)

来源:网络收集 时间:2026-09-28
导读: 46. } 做了这么多工作,有人又会问,怎么现在做的与spring框架就没一点联系,呵呵,确实是这样。开戏开场了,利用Spring来发布WebService接口: Java代码 1. 2. 6. http://www.springframework.org/schema/beans 7.

46. }

做了这么多工作,有人又会问,怎么现在做的与spring框架就没一点联系,呵呵,确实是这样。开戏开场了,利用Spring来发布WebService接口: Java代码

1.

2.

6. http://www.springframework.org/schema/beans

7. http://www.springframework.org/schema/beans/spring-beans-2.0.xsd 8. http://cxf.apache.org/jaxws

9. http://cxf.apache.org/schemas/jaxws.xsd\10. [color=red]

11.

12.

13.

16. 17.

18. implementor=\19.

20. 21.

服务端开发工作基本结束。现在打包部署到Tomcat6.0.18(本人目前使用的测试服务器,你当然可以使用别的服务器)

服务器启动完成后,打开浏览器在地址栏中输入http://localhost:port/project name/Service?wsdl看看接口是否发成功。

接下来就是开发一个客户端了。

另建一个web project,现在前面的参数配置要起作用了,cmd进入DOS环境下输入wsdl2java -p com.itdcl.service(自定义包名) http://localhost:port/project name/Service?wsdl(前提是服务器没停止)

敲击Enter,wsdl2java工具帮你将发布出来的wsdl文件转换成webservice接口,到指定目录下将com.itdcl.service拷到刚才另建的web project的src目录下。 现在,我们就来创建一个客户端程序: Java代码

1. public class SampleClient { 2.

3. ublic static void main(String[] args) {

4. ApplicationContext context = new ClassPathXmlApplicationContext( 5. \6.

7. IService service = (IService)context.getBean(\8. ServerUserInfo userInfo = new ServerUserInfo(); 9. userInfo.setAddress(1); 10. userInfo.setAge(100); 11. userInfo.setName(\12.

13. service.save(userInfo,true); 14. service.delete(1); 15. 16. 17. }

看得仔细的朋友就会问了,ServerUserInfo 这个类那来的,你进到com.itdcl.service目录下就会看到,是WebService发布出来的。

到目前为止,客户端还没有完成,你没有看到程序中ApplicationContext context = new

ClassPathXmlApplicationContext(\这个bean.xml就是spring框架来注删除WebService接口的。好啦,创建一个bean.xml,内容如下: Java代码

1.

2.

6. http://www.springframework.org/schema/beans

7. http://www.springframework.org/schema/beans/spring-beans-2.0.xsd 8. [color=red]http://cxf.apache.org/jaxws

9. http://cxf.apache.org/schemas/jaxws.xsd[/color]\10.

11. address=\12. serviceClass=\13.

留意一下绿色字体

剩下的事就是运行客户端程序了,没有异常抛出,打印出:name:Josen,则恭喜你CXF框架与Spring整合成功。

WebService CXF学习(高级篇2):CXF+Spring+Hibernate 前一节仅仅只讲了与Spring整合,没有涉及到数据库,而且是直接将Java象传递到服务端。这一节我起到一个回顾前面章节的作用。用在客户端运用JABX将JAVA对象编组成XML文件,在客户端将XML解组成

JAVA并存入数据库。下面我们就着手开发这个Demo: 服务端开发

第一步,编写数据资源层相关接口 DAO编写: Java代码

1. public interface HibernateDao { 2.

3. public void save(UserInfo object); 4. public void delete(UserInfo object); 5. public void update(UserInfo object); 6. public UserInfo get(int id); 7. } 8.

DAO实现类: Java代码

1. public class HibernateDaoImpl extends HibernateDaoSupport implements HibernateDao {

2.

3. public void delete(UserInfo object) {

4. this.getHibernateTemplate().delete(object); 5. } 6.

7. public void save(UserInfo object) {

8. this.getHibernateTemplate().save(object); 9. } 10.

11. public void update(UserInfo object) {

12. this.getHibernateTemplate().update(object); 13. } 14.

15. public UserInfo get(int id) {

16. return (UserInfo) this.getHibernateTemplate().get(UserInfo.class, id); 17. } 18. 19. }

实体对象: Java代码

1. @Entity

2. @Table(name = \

3. public class UserInfo implements java.io.Serializable { 4.

5. private static final long serialVersionUID = 2281022190032353574L; 6. 7. @Id

8. @GeneratedValue(strategy = GenerationType.IDENTITY) 9. private Integer id; 10. private String name; 11. private Integer age; 12. private Integer address; 13.

14. public UserInfo() { 15. } 16.

17. public UserInfo(String name, Integer age) { 18. this.name = name; 19. this.age = age; 20. } 21.

22. public UserInfo(String name, Integer age, Integer address) { 23. this.name = name; 24. this.age = age;

25. this.address = address; 26. } 27.

28. public Integer getId() { 29. return this.id; 30. } 31.

32. public void setId(Integer id) { 33. this.id = id; 34. } 35.

36. public String getName() { 37. return this.name; 38. } 39.

40. public void setName(String name) { 41. this.name = name; 42. } 43.

44. public Integer getAge() {

45. return this.age; 46. } 47.

48. public void setAge(Integer age) { 49. this.age = age; 50. } 51.

52. public Integer getAddress() { …… 此处隐藏:2468字,全部文档内容请下载后查看。喜欢就下载吧 ……

WebService CXF学习(8).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.jiaowen.net/wendang/446324.html(转载请注明文章来源)
Copyright © 2020-2025 教文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:78024566 邮箱:78024566@qq.com
苏ICP备19068818号-2
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150份
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150份
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)