java webservice bean_用Spring创建的JavaBean发布成Webservice

1. 服务端代码:

public class SpringService {

private String name;

private int number;

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public int getNumber() {

return number;

}

public void setNumber(int number) {

this.number = number;

}

public String getMessage() {

return this.number + "#" + this.name;

}

}

2.  在/webapps/axis2/WEB-INF/web.xml文件中加入下面的内容:

org.springframework.web.context.ContextLoaderListenercontextConfigLocationclasspath*:applicationContext.xml

3.  在[tomcat-home]/webapps/axis2/WEB-INF/classes中新建一个applicationContext.xml文件,文件中的内容如下:

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

4. 在axis项目的lib包中如果无对应的spring包,需要添加spring.jar等相关jar包

5. 编写services.xml,打包,并发布至对应目录

Spring aware

org.apache.axis2.extensions.spring.receivers.SpringServletContextObjectSupplier

SpringBeanService

class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />

6. 编写客户端代码:

package client;

import javax.xml.namespace.QName;

import org.apache.axis2.AxisFault;

import org.apache.axis2.addressing.EndpointReference;

import org.apache.axis2.client.Options;

import org.apache.axis2.rpc.client.RPCServiceClient;

public class SpringTest {

public static void main(String[] args) throws AxisFault {

String target = "http://localhost:8080/axis2/services/springService";

RPCServiceClient client = new RPCServiceClient();

Options options = client.getOptions();

options.setManageSession(true);

EndpointReference epr = new EndpointReference(target);

options.setTo(epr);

QName qname = new QName("http://spring.server", "getMessage");

Object[] result = client.invokeBlocking(qname, new Object[] { null },

new Class[] { String.class });

System.out.println(result[0]);

}

}

运行后,看到bean注入的值有输出。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值