zno2

配置 cxf-ws spring bean 文件

<?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: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">

<!-- 
    cxf-rt-core-2.1.3.jar
    cxf-rt-bindings-soap-2.1.3.jar 
    cxf-rt-transports-http-2.1.3.jar 
-->
    <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="org.apache.cxf.HelloWorldImpl"
        address="/HelloWorld" />

</beans>

1. import

cxf.xml 位于 cxf-rt-core-2.1.3.jar

<?xml version="1.0" encoding="UTF-8"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one
  or more contributor license agreements. See the NOTICE file
  distributed with this work for additional information
  regarding copyright ownership. The ASF licenses this file
  to you under the Apache License, Version 2.0 (the
  "License"); you may not use this file except in compliance
  with the License. You may obtain a copy of the License at
 
  http://www.apache.org/licenses/LICENSE-2.0
 
  Unless required by applicable law or agreed to in writing,
  software distributed under the License is distributed on an
  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  KIND, either express or implied. See the License for the
  specific language governing permissions and limitations
  under the License.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:foo="http://cxf.apache.org/configuration/foo"
       xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

    <bean id="cxf" class="org.apache.cxf.bus.CXFBusImpl"/>
    <bean id="org.apache.cxf.bus.spring.BusWiringBeanFactoryPostProcessor" class="org.apache.cxf.bus.spring.BusWiringBeanFactoryPostProcessor"/>
    <bean id="org.apache.cxf.bus.spring.Jsr250BeanPostProcessor" class="org.apache.cxf.bus.spring.Jsr250BeanPostProcessor"/>    
    <bean id="org.apache.cxf.bus.spring.BusExtensionPostProcessor" class="org.apache.cxf.bus.spring.BusExtensionPostProcessor"/>
    
    <bean id="org.apache.cxf.resource.ResourceManager" class="org.apache.cxf.bus.resource.ResourceManagerImpl">
       <property name="resolvers">
            <list>
                <bean class="org.apache.cxf.resource.ClasspathResolver"/>
                <bean class="org.apache.cxf.resource.ClassLoaderResolver"/>
                <bean class="org.apache.cxf.bus.spring.BusApplicationContextResourceResolver"/>
            </list>
       </property>
       <property name="bus" ref="cxf"/>
    </bean>
    <bean id="org.apache.cxf.configuration.Configurer" 
        class="org.apache.cxf.configuration.spring.ConfigurerImpl">
    </bean>    
        
    <bean id="org.apache.cxf.binding.BindingFactoryManager" class="org.apache.cxf.binding.BindingFactoryManagerImpl">
        <property name="mapProvider">
            <bean class="org.apache.cxf.configuration.spring.SpringBeanMap">
              <property name="type" value="org.apache.cxf.binding.BindingFactory"/>
              <property name="idsProperty" value="activationNamespaces"/>
            </bean>
        </property>
        <property name="bus" ref="cxf"/>
    </bean>
    
    <bean id="org.apache.cxf.transport.DestinationFactoryManager" class="org.apache.cxf.transport.DestinationFactoryManagerImpl">
        <property name="mapProvider">
            <bean class="org.apache.cxf.configuration.spring.SpringBeanMap">
              <property name="type" value="org.apache.cxf.transport.DestinationFactory"/>
              <property name="idsProperty" value="transportIds"/>
            </bean>
        </property>
        <property name="bus" ref="cxf"/>
    </bean>
    
    <bean id="org.apache.cxf.transport.ConduitInitiatorManager" class="org.apache.cxf.transport.ConduitInitiatorManagerImpl">
        <property name="mapProvider">
            <bean class="org.apache.cxf.configuration.spring.SpringBeanMap">
              <property name="type" value="org.apache.cxf.transport.ConduitInitiator"/>
              <property name="idsProperty" value="transportIds"/>
            </bean>
        </property>
        <property name="bus" ref="cxf"/>
    </bean>
    
    <bean id="org.apache.cxf.wsdl.WSDLManager" class="org.apache.cxf.wsdl11.WSDLManagerImpl">
        <property name="bus" ref="cxf"/>
    </bean>
    
    <bean id="org.apache.cxf.phase.PhaseManager" class="org.apache.cxf.phase.PhaseManagerImpl">
        
    </bean>
    
    <bean id="org.apache.cxf.workqueue.WorkQueueManager" class="org.apache.cxf.workqueue.WorkQueueManagerImpl">
        <property name="bus" ref="cxf"/>
    </bean>
    
    <bean id="org.apache.cxf.buslifecycle.BusLifeCycleManager" class="org.apache.cxf.buslifecycle.CXFBusLifeCycleManager">
        <property name="bus" ref="cxf"/>
    </bean>
    
    <bean id="org.apache.cxf.endpoint.ServerRegistry" class="org.apache.cxf.endpoint.ServerRegistryImpl">
        <property name="bus" ref="cxf"/>
    </bean>

    <bean id="org.apache.cxf.endpoint.ServerLifeCycleManager" class="org.apache.cxf.endpoint.ServerLifeCycleManagerImpl"/>
    <bean id="org.apache.cxf.endpoint.ClientLifeCycleManager" class="org.apache.cxf.endpoint.ClientLifeCycleManagerImpl"/>
        

    <bean id="org.apache.cxf.transports.http.QueryHandlerRegistry" class="org.apache.cxf.transport.http.QueryHandlerRegistryImpl">
        <property name="bus" ref="cxf"/>
        <property name="queryHandlers">
            <list>
                <bean class="org.apache.cxf.transport.http.WSDLQueryHandler">
                    <property name="bus" ref="cxf"/>
                </bean>    
            </list>
        </property>
    </bean>

    <bean id="org.apache.cxf.endpoint.EndpointResolverRegistry" class="org.apache.cxf.endpoint.EndpointResolverRegistryImpl">
        <property name="bus" ref="cxf"/>
    </bean>
    <bean id="org.apache.cxf.headers.HeaderManager" class="org.apache.cxf.headers.HeaderManagerImpl">
        <property name="bus" ref="cxf"/>
    </bean>
    <bean id="org.apache.cxf.catalog.OASISCatalogManager" class="org.apache.cxf.catalog.OASISCatalogManager">
        <property name="bus" ref="cxf"/>
    </bean>

    <bean id="org.apache.cxf.endpoint.ServiceContractResolverRegistry" class="org.apache.cxf.endpoint.ServiceContractResolverRegistryImpl">
        <property name="bus" ref="cxf"/>
    </bean>
</beans>
View Code

定义了id 是 cxf 的bean ,以供其他bean 引用。

定义了其他bean

cxf-extension-soap.xml 位于cxf-rt-bindings-soap-2.1.3.jar

<?xml version="1.0" encoding="UTF-8"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one
  or more contributor license agreements. See the NOTICE file
  distributed with this work for additional information
  regarding copyright ownership. The ASF licenses this file
  to you under the Apache License, Version 2.0 (the
  "License"); you may not use this file except in compliance
  with the License. You may obtain a copy of the License at
 
  http://www.apache.org/licenses/LICENSE-2.0
 
  Unless required by applicable law or agreed to in writing,
  software distributed under the License is distributed on an
  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  KIND, either express or implied. See the License for the
  specific language governing permissions and limitations
  under the License.
-->

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:foo="http://cxf.apache.org/configuration/foo"
       xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
    
    <bean id="org.apache.cxf.binding.soap.SoapBindingFactory"
      class="org.apache.cxf.binding.soap.SoapBindingFactory" lazy-init="true">
        <property name="activationNamespaces">
            <set>
                <value>http://schemas.xmlsoap.org/soap/</value>
                <value>http://schemas.xmlsoap.org/wsdl/soap/</value>
                <value>http://schemas.xmlsoap.org/wsdl/soap12/</value>
                <value>http://www.w3.org/2003/05/soap/bindings/HTTP/</value>
                <value>http://schemas.xmlsoap.org/wsdl/soap/http</value>
            </set>
        </property>
        <property name="bus" ref="cxf"/>
    </bean>
    
    <bean class="org.apache.cxf.binding.soap.SoapTransportFactory"
      id="org.apache.cxf.binding.soap.SoapTransportFactory"
      lazy-init="true">
        <property name="transportIds">
            <list>
                <value>http://schemas.xmlsoap.org/soap/</value>
                <value>http://schemas.xmlsoap.org/wsdl/soap/</value>
            <value>http://schemas.xmlsoap.org/wsdl/soap12/</value>
            </list>
        </property>
        <property name="bus" ref="cxf"/>
    </bean>
        
    <bean id="org.apache.cxf.binding.soap.customEditorConfigurer"
        class="org.springframework.beans.factory.config.CustomEditorConfigurer">
        <property name="customEditors">
            <map>
                <entry key="org.apache.cxf.binding.soap.SoapVersion">
                    <bean class="org.apache.cxf.binding.soap.SoapVersionEditor"/>
                </entry>
            </map>
        </property>
    </bean>
</beans>
View Code

cxf-servlet.xml 位于 cxf-rt-transports-http-2.1.3.jar

<?xml version="1.0" encoding="UTF-8"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one
  or more contributor license agreements. See the NOTICE file
  distributed with this work for additional information
  regarding copyright ownership. The ASF licenses this file
  to you under the Apache License, Version 2.0 (the
  "License"); you may not use this file except in compliance
  with the License. You may obtain a copy of the License at
 
  http://www.apache.org/licenses/LICENSE-2.0
 
  Unless required by applicable law or agreed to in writing,
  software distributed under the License is distributed on an
  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  KIND, either express or implied. See the License for the
  specific language governing permissions and limitations
  under the License.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:foo="http://cxf.apache.org/configuration/foo"
       xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
            
    <bean class="org.apache.cxf.transport.servlet.ServletTransportFactory"
      id="org.apache.cxf.transport.servlet.ServletTransportFactory">
        <property name="bus" ref="cxf"/>
        <property name="transportIds">
            <set>
                <value>http://cxf.apache.org/bindings/xformat</value>
                <value>http://schemas.xmlsoap.org/soap/http</value>
                <value>http://schemas.xmlsoap.org/wsdl/http/</value>
                <value>http://schemas.xmlsoap.org/wsdl/soap/http</value>
                 <value>http://www.w3.org/2003/05/soap/bindings/HTTP/</value>
                <value>http://cxf.apache.org/transports/http/configuration</value>                
            </set>
        </property>
    </bean>
</beans>
View Code

2. jaxws

http://cxf.apache.org/schemas/jaxws.xsd

这个xml语法定义中提供了三个:

  • <jaxws:endpoint></jaxws:endpoint>
  • <jaxws:server></jaxws:server>
  • <jaxws:client></jaxws:client>

endpoint 与 server 的区别

cxf的发布方式↓

package ws.run;

import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor;
import org.apache.cxf.jaxws.JaxWsServerFactoryBean;

import cn.zno.ws.service.CleanService;
import cn.zno.ws.serviceImpl.CleanServiceImpl;

public class Run {

    public static void main(String[] args) {
        CleanServiceImpl implementor = new CleanServiceImpl();
        JaxWsServerFactoryBean svrFactory = new JaxWsServerFactoryBean();
        svrFactory.setServiceClass(CleanService.class);
        svrFactory.setAddress("http://localhost:9000/clean");
        svrFactory.setServiceBean(implementor);
        svrFactory.getInInterceptors().add(new LoggingInInterceptor());
        svrFactory.getOutInterceptors().add(new LoggingOutInterceptor());
        svrFactory.create();
    }
}

标准的发布服务方式↓

package ws.run;

import javax.xml.ws.Endpoint;

import cn.zno.ws.serviceImpl.CleanServiceImpl;


public class Run {

    public static void main(String[] args) {
        Endpoint.publish("http://localhost:9000/clean", new CleanServiceImpl());
    }
}

 

posted on 2016-08-02 22:02  zno2  阅读(394)  评论(0)    收藏  举报

导航