cxf+spring发布webservice服务(客户端)

我不是女神ヾ 2022-06-13 06:24 399阅读 0赞

首先创建接口,与服务器一样的接口

  1. @WebService
  2. public interface HelloWorld {
  3. public String sayHello(String name);
  4. }

再在classpath下新建beans.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans
  3. xmlns="http://www.springframework.org/schema/beans"
  4. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  5. xmlns:jaxws="http://cxf.apache.org/jaxws"
  6. xsi:schemaLocation="http://www.springframework.org/schema/beans
  7. http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
  8. http://cxf.apache.org/jaxws
  9. http://cxf.apache.org/schemas/jaxws.xsd">
  10. <jaxws:client
  11. id="cxfClient"
  12. address="http://localhost:8080/cxf-Spring-server/Hello"
  13. serviceClass="com.spg.cxfSpring.dao.HelloWorld" />
  14. </beans>

最后在编写客户端代码,调用服务器端的接口

  1. public class Client {
  2. public static void main(String[] args) {
  3. BeanFactory factory = new ClassPathXmlApplicationContext("beans.xml");
  4. HelloWorld hello = (HelloWorld) factory.getBean("cxfClient");
  5. System.out.println(hello.sayHello("spg"));
  6. }
  7. }

运行结果,得到服务器端的返回数据。

发表评论

表情:
评论列表 (有 0 条评论,399人围观)

还没有评论,来说两句吧...

相关阅读