CXF之spring配置实例(Simple Frontend)

 

CXF包含一个从反射构建服务的simple frontend. 对比JAX-WS frontend,JAX-WS frontend必须注解你的web服务类或从wsdl first开发创建。simple frontend使用反射来智能映射你的类到wsdl模型上,不用注解。默认使用JAXB数据绑定。 你也可以使用Aegis梆定.

 

 

服务接口:

package server; public interface HelloWorld { String sayHi(String name); }  

 

服务实现类:

package server; public class HelloWorldImpl implements HelloWorld { @Override public String sayHi(String name) { System.out.println("server: " + name); return name+"--client"; } }  

 

spring配置服务端:

<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:simple="http://cxf.apache.org/simple" xmlns:soap="http://cxf.apache.org/bindings/soap" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://cxf.apache.org/bindings/soap http://cxf.apache.org/schemas/configuration/soap.xsd http://cxf.apache.org/simple http://cxf.apache.org/schemas/simple.xsd"> <import resource="classpath:META-INF/cxf/cxf.xml" /> <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" /> <import resource="classpath:META-INF/cxf/cxf-servlet.xml" /> <simple:server id="helloWorlderver" serviceClass="server.HelloWorld" address="/helloworld"> <simple:serviceBean> <bean class="server.HelloWorldImpl" /> </simple:serviceBean> </simple:server> </beans> 

 

spring配置客户端:

<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:simple="http://cxf.apache.org/simple" xmlns:soap="http://cxf.apache.org/bindings/soap" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://cxf.apache.org/bindings/soap http://cxf.apache.org/schemas/configuration/soap.xsd http://cxf.apache.org/simple http://cxf.apache.org/schemas/simple.xsd"> <simple:client id="client" serviceClass="server.HelloWorld" address="http://localhost:8085/cxf-simple-frontend-test/service/helloworld"> </simple:client> </beans>  

 

客户端调用代码:

package client; import org.springframework.context.support.ClassPathXmlApplicationContext; import server.HelloWorld; public class HelloWorldClient { public static void main(String[] args) { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( new String[] { "client-beans.xml" }); HelloWorld hw = (HelloWorld) context.getBean("client"); String returnStr = hw.sayHi("fuhaidong"); System.out.println(returnStr); } }  

你可能感兴趣的:(spring,String,JAXB,Class,SOAP,encoding)