How-Tos_Writing a service with spring
来源:互联网 发布:农村淘宝要投资多少钱 编辑:程序博客网 时间:2024/06/06 06:32
使用spring构件第一个Web服务,项目名java_first_spring_support
构件项目
编写服务
接口:
<span style="font-size:18px;">import javax.jws.WebService; @WebServicepublic interface HelloWorld { String sayHi(String text);}</span>接口实现:
<span style="font-size:18px;">import javax.jws.WebService; @WebService(endpointInterface = "demo.spring.service.HelloWorld")public class HelloWorldImpl implements HelloWorld { public String sayHi(String text) { System.out.println("sayHi called"); return "Hello " + text; }}</span>
实现类的@ webservice注释让CXF知道使用哪个接口在创建WSDL。
声明服务的beans
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"> <import resource="classpath:META-INF/cxf/cxf.xml"/> <import resource="classpath:META-INF/cxf/cxf-servlet.xml"/> <jaxws:endpoint id="helloWorld" implementor="demo.spring.service.HelloWorldImpl" address="/HelloWorld"/></beans>配置servlet
例子:
<web-app ...>... <context-param> <param-name>contextConfigLocation</param-name> <param-value>WEB-INF/beans.xml</param-value> </context-param> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener></web-app>
创建客户端(easy way)
客户端bean
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:jaxws="http://cxf.apache.org/jaxws" 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.xsdhttp://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"> <jaxws:client id="helloClient" serviceClass="demo.spring.HelloWorld" address="http://localhost:9002/HelloWorld" /></beans>创建客户端(More Manual Way)
使用JaxWsProxyFactory从服务接口创建一个客户端
客户端bean:
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schema/jaxws.xsd"> <bean id="client" class="demo.spring.service.HelloWorld" factory-bean="clientFactory" factory-method="create"/> <bean id="clientFactory" class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean"> <property name="serviceClass" value="demo.spring.service.HelloWorld"/> <property name="address" value="http://localhost:9002/services/HelloWorld"/> </bean></beans>
客户端代码:
<pre name="code" class="html">ApplicationContext context = ...; // your Spring ApplicationContextHelloWorld client = (HelloWorld) context.getBean("client");
0 0
- How-Tos_Writing a service with spring
- cxf-Writing a service with Spring
- How to Build a RESTful API Web Service with PHP
- How can a singleton bean collaborate with a non-singleton one in Spring
- How To Start An Spring Application-Building a RESTful Web Service
- How to respond with HTTP 400 error in a Spring MVC @ResponseBody method returning String?
- WSSF:ME - how to consume a service
- How to: Access a Duplex Service
- How to add a Linux service
- How do I develop a service?
- how to begin with a new project
- How to Do Research With a Professor
- How to build a product with InstallShield
- How To Design a Class With Matlab
- How weblogicJTA works with spring JTA
- 如何删除windows service (How to delete a windows service)
- Interacting with the User in a Service
- Creating a Web Service with JAX-RPC
- Failed to configure driver: unknown error. Failed to open driver
- 大家好,我叫小白。
- 资产折旧盘点表
- 【教育】这么多年的应试教育,成果几何?
- Zookeeper客户端cli_st为何在crontab中运行不正常?
- How-Tos_Writing a service with spring
- Android Studio逆向工程——向Eclipse迁移
- UVa11624大火蔓延的迷宫(代码觉得没问题,但是对答案是3有疑惑,而且没有在oj上验证)
- Visual Studio Code + Golang1.5 debug + MAC OS X 10.11
- 大整数类的应用 bjfu1005
- 通过 WebBrowser 获取网页截图
- 键盘的相关设置
- 经典排序算法(一)冒泡法排序----C++实现
- 使用svn后无法打开程序