国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

axis2+spring集成

2019-11-14 21:22:02
字體:
來源:轉載
供稿:網友
axis2+sPRing集成轉載自:http://www.survivalescaperooms.com/linjiqin/archive/2011/07/05/2098316.html1、新建一個web project項目,最終工程目錄如下:

注意:本文只注重webservice服務器端的開發,因此com.ljq.client和com.ljq.test忽略不計

2、添加所需jar

精簡包

3、接口HelloWorld

package com.ljq.service;public interface HelloWorld {    public String greeting(String name);    public String print();}

4、接口實現類HelloWorldBean

復制代碼
package com.ljq.service;public class HelloWorldBean implements HelloWorld {    public String greeting(String name) {        return "你好 "+name;    }    public String print() {        return "我叫林計欽";    }}
復制代碼

5、webservice類HelloWorldWebService

復制代碼
package com.ljq.service;import org.apache.axis2.AxisFault;import org.apache.axis2.ServiceObjectSupplier;import org.apache.axis2.description.AxisService;import org.apache.axis2.description.Parameter;import org.apache.axis2.i18n.Messages;import org.springframework.beans.BeansException;import org.springframework.context.applicationContext;import org.springframework.context.ApplicationContextAware;/** * 可能出現Axis2 spring bean not found 或者 Spring applicationContext not found。 *  * 解決辦法:構建自己的ServiceObjectSupplier,實現接口ServiceObjectSupplier,同時也實現Spring的ApplicationContextAware接口 *  *  * @author Administrator *  */public class HelloWorldWebService implements ServiceObjectSupplier,        ApplicationContextAware {    private static ApplicationContext ctx;    public Object getServiceObject(AxisService axisService) throws AxisFault {        Parameter springBeanName = axisService.getParameter("SpringBeanName");        String beanName = ((String) springBeanName.getValue()).trim();        if (beanName != null) {            if (ctx == null)                throw new AxisFault("applicationContext is NULL! ");            if (ctx.getBean(beanName) == null)                throw new AxisFault("Axis2 Can't find Spring Bean: " + beanName);            return ctx.getBean(beanName);        } else {            throw new AxisFault(Messages.getMessage("paramIsNotSpecified",                    "SERVICE_SPRING_BEANNAME"));        }    }    public void setApplicationContext(ApplicationContext ctx)            throws BeansException {        this.ctx = ctx;    }}
復制代碼

6、配置web.xml文件

復制代碼
<?xml version="1.0" encoding="UTF-8"?><web-app version="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">    <!-- 添加spring監聽器 -->    <listener>        <listener-class>            org.springframework.web.context.ContextLoaderListener        </listener-class>    </listener>    <!-- 加載spring的配置文件 -->    <context-param>        <param-name>contextConfigLocation</param-name>        <param-value>/WEB-INF/applicationContext.xml</param-value>    </context-param>        <!-- 注冊axis2的servlet -->    <servlet>        <servlet-name>AxisServlet</servlet-name>        <servlet-class>            org.apache.axis2.transport.http.AxisServlet        </servlet-class>        <load-on-startup>1</load-on-startup>    </servlet>    <servlet-mapping>        <servlet-name>AxisServlet</servlet-name>        <url-pattern>/services/*</url-pattern>    </servlet-mapping>    <welcome-file-list>        <welcome-file>index.jsp</welcome-file>    </welcome-file-list></web-app>
復制代碼

7、在WEB-INF目錄下配置applicationContext.xml(不存在則自己創建)

復制代碼
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN""http://www.springframework.org/dtd/spring-beans.dtd"><beans>    <bean id="applicationContext"        class="org.apache.axis2.extensions.spring.receivers.ApplicationContextHolder" />    <bean id="helloWorld" class="com.ljq.service.HelloWorldBean"></bean></beans>
復制代碼

8、在WEB-INF/services/axis/META-INF/目錄下配置services.xml(不存在則自己創建)

復制代碼
<?xml version="1.0" encoding="UTF-8"?><service name="hwWebService">    <description>axis2與spring集成案例</description>    <!-- 通過ServiceObjectSupplier參數指定SpringServletContextObjectSupplier類來獲得Spring的ApplicationContext對象 -->    <parameter name="ServiceObjectSupplier">        org.apache.axis2.extensions.spring.receivers.SpringAppContextAwareObjectSupplier    </parameter>    <!--        SpringBeanName固定的不能改       helloWorld是spring中注冊的實現類得id     -->    <parameter name="SpringBeanName">helloWorld</parameter>    <!--     在這里最值得注意的是<messageReceivers>元素,該元素用于設置處理WebService方法的處理器。    例如,getGreeting方法有一個返回值,因此,需要使用可處理輸入輸出的RPCMessageReceiver類,    而update方法沒有返回值,因此,需要使用只能處理輸入的RPCInOnlyMessageReceiver類。     -->    <messageReceivers>        <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only"            class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver" />        <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out"            class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />    </messageReceivers></service>
復制代碼

axis2+spring集成到此已經開發完成,接下把工程部署到tomcat,

然后通過http://localhost:8083/axis2spring/services/hwWebService?wsdl訪問


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 崇左市| 兴化市| 五家渠市| 保定市| 车致| 普安县| 交城县| 应城市| 永昌县| 依安县| 海宁市| 保靖县| 武清区| 阳曲县| 阜新市| 白山市| 承德市| 乳源| 晋宁县| 南澳县| 保定市| 始兴县| 汤原县| 吴堡县| 盐边县| 东辽县| 永新县| 隆林| 于都县| 荔波县| 扎鲁特旗| 新泰市| 大关县| 南通市| 襄樊市| 富顺县| 淮阳县| 河南省| 林州市| 闸北区| 时尚|