欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

cxf+web service(四)cxf+spring集成

程序员文章站 2022-05-18 09:31:03
...

客户端

public class Client {

	private Client(){}
	
	public static void main(String[] args) {
		ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext-client.xml");
        HelloWorld hw = (HelloWorld) context.getBean("client");
        String response = hw.zhuce("piter", "123456");
        System.out.println(response);
	}
}

 客户端配置文件,这里面配置代理工厂,地址,暴露的服务接口.这里也可以直接在客户端代码里面使用JaxWsProxyFactoryBean来发布

 <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"/>

    <bean id="client" class="com.cxf.test.HelloWorld" factory-bean="clientFactory" factory-method="create" />

    <bean id="clientFactory" class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean">
        <property name="serviceClass" value="com.cxf.test.HelloWorld" />
        <property name="address" value="http://localhost:8080/cxf/ws/HelloWorld" />
    </bean>

 然后在spring.xml中加入接口的配置

<!-- Import Apache CXF Bean Definition -->
    <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"/>

    <jaxws:endpoint id="helloWorld" 
    	implementor="com.cxf.test.HelloWorldImpl" 
    	address="/HelloWorld"/>

 OK,最后在浏览器输入http://localhost:8080/cxf/ws,如下图,发布成功!


cxf+web service(四)cxf+spring集成
            
    
    博客分类: cxf+web service cxfweb service 
 运行客户端main方法,控制台输出,注册成功.

  • cxf+web service(四)cxf+spring集成
            
    
    博客分类: cxf+web service cxfweb service 
  • 大小: 36.6 KB
相关标签: cxf web service