圆舞曲风格:webservice 笔记(小结) axis2 集成spring <一>发布服务 - Th...
来源:百度文库 编辑:中财网 时间:2024/04/29 04:12:36
2009-05-17
首先我们选的是axis2-1.4 +myeclipse6.5+tomcat 6.0,大家肯定不陌生了。我们以前都是把从官网上下载的war包考到tomcat的webapps下,但是现在我们自己建一个web项目
1、首先建立一个web工程,名字叫WebService,
2、把相应的axis2的jar文件考到WEB-INF的lib下
3、 在项目的WebRoot下的目录结构要和以前用war包是的目录结构一样(否则可能就要报 错了)
目录结构如图所示:
4、在src下建立package sample.service
5、建立提供服务的接口
Java代码
实现类:
Java代码
6、在src下建立applicationContext.xml文件
配置如下
Java代码
7、在WebRoor/WEB-INF/services/目录下建立目录sampleService(这个名字可以随便取)
然后建立在其下META-INF目录,然后再在其目录下建立services.xml
目录结构如下
services.xml的内容如下:
Java代码
8、现在要配置一下web.xml了
内容如下:
Java代码
9、启动tomcat 在浏览器中输入http://localhost:8080/WebService/services/listServices
可以看到一下内容说明我们的服务已经发布成功了
访问
http://localhost:8080/WebService/services/HelloWorld?wsdl
可以查看wsdl
待会就是访问我们的服务了(用axis2 的eclipse 插件自动生成客户端),
如果有问题可以加群 : 84242283(webservice交流学习)
webservice 笔记(小结) axis2 集成spring <一>发布服务
学习了一段时间的webservice,今天有空,稍微总结一下。首先我们选的是axis2-1.4 +myeclipse6.5+tomcat 6.0,大家肯定不陌生了。我们以前都是把从官网上下载的war包考到tomcat的webapps下,但是现在我们自己建一个web项目
1、首先建立一个web工程,名字叫WebService,
2、把相应的axis2的jar文件考到WEB-INF的lib下
3、 在项目的WebRoot下的目录结构要和以前用war包是的目录结构一样(否则可能就要报 错了)
目录结构如图所示:
4、在src下建立package sample.service
5、建立提供服务的接口
Java代码
- package sample.service;
- /**
- * 定义服务接口
- * @author 11111
- *
- */
- public interface ServiceServer {
- //定义服务方法
- public String sayHello(String name);
- }
package sample.service;/*** 定义服务接口* @author 11111**/public interface ServiceServer {//定义服务方法public String sayHello(String name);}
实现类:
Java代码
- package sample.service;
- public class ServiceServerImpl implements ServiceServer {
- public String sayHello(String name) {
- return "hello"+name;
- }
- }
package sample.service;public class ServiceServerImpl implements ServiceServer {public String sayHello(String name) {return "hello"+name;}}
6、在src下建立applicationContext.xml文件
配置如下
Java代码
- "1.0" encoding="UTF-8"?>
"http://www.springframework.org/schema/beans" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:aop="http://www.springframework.org/schema/aop"
- xmlns:tx="http://www.springframework.org/schema/tx"
- xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
- http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
- http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
"SayHelloService" class="sample.service.ServiceServerImpl">
7、在WebRoor/WEB-INF/services/目录下建立目录sampleService(这个名字可以随便取)
然后建立在其下META-INF目录,然后再在其目录下建立services.xml
目录结构如下
services.xml的内容如下:
Java代码
- "1.0" encoding="UTF-8"?>
"HelloWorld"> web service "ServiceObjectSupplier"> - org.apache.axis2.extensions.spring.receivers.SpringServletContextObjectSupplier
"SpringBeanName">SayHelloService - //SpringBeanName名字是固定的不能改
- //SayHelloService是spring中注册的实现类的id(这个大家肯定很清楚了)
"sayHello"> class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
web service org.apache.axis2.extensions.spring.receivers.SpringServletContextObjectSupplier SayHelloService //SpringBeanName名字是固定的不能改//SayHelloService是spring中注册的实现类的id(这个大家肯定很清楚了)
8、现在要配置一下web.xml了
内容如下:
Java代码
- "1.0" encoding="UTF-8"?>
"2.5" - xmlns="http://java.sun.com/xml/ns/javaee"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
- http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
AxisServlet - //注册axis2的servlet
class>org.apache.axis2.transport.http.AxisServlet class>1 AxisServlet /services/* - //加载spring的配置文件
contextConfigLocation classpath*:applicationContext.xml - //增加spring监听器
class>org.springframework.web.context.ContextLoaderListener class>
AxisServlet //注册axis2的servletorg.apache.axis2.transport.http.AxisServlet 1 //加载spring的配置文件 AxisServlet /services/* //增加spring监听器 contextConfigLocation classpath*:applicationContext.xml org.springframework.web.context.ContextLoaderListener
9、启动tomcat 在浏览器中输入http://localhost:8080/WebService/services/listServices
可以看到一下内容说明我们的服务已经发布成功了
访问
http://localhost:8080/WebService/services/HelloWorld?wsdl
可以查看wsdl
待会就是访问我们的服务了(用axis2 的eclipse 插件自动生成客户端),
如果有问题可以加群 : 84242283(webservice交流学习)