1

Spring 構成なしで SOAP サービスを登録する必要があります。RESTFUL サービスの場合は (CXFNonSpringJaxrsServlet を使用して web.xml で構成することにより) それが可能であることはわかっていますが、SOAP サービスに同様のものを使用するにはどうすればよいでしょうか? これは私の元のapplicationContext.xmlです:

<?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:cxf="http://cxf.apache.org/core"
   xmlns:jaxws="http://cxf.apache.org/jaxws"
   xmlns:jaxrs="http://cxf.apache.org/jaxrs"
   xsi:schemaLocation="
   http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
   http://cxf.apache.org/core
   http://cxf.apache.org/schemas/core.xsd
   http://cxf.apache.org/jaxws
   http://cxf.apache.org/schemas/jaxws.xsd
   http://cxf.apache.org/jaxrs
   http://cxf.apache.org/schemas/jaxrs.xsd"
   default-autowire="byName">


<!-- Load CXF modules from cxf.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"/>
<import resource="classpath:META-INF/cxf/cxf-extension-jaxrs-binding.xml"/>

<bean id="businessServiceabilityService" 
      class="XXXXXXXXXXXXXXXXXXServiceImpl"
      autowire="autodetect"/>
<bean id="jaxbBean"
      class="org.apache.cxf.jaxb.JAXBDataBinding"
      scope="prototype"/>
<bean id="jaxws-and-aegis-service-factory"
      class="org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean"
      scope="prototype">
    <property name="dataBinding" ref="jaxbBean"/>
    <property name="serviceConfigurations">
        <list>
            <bean class="org.apache.cxf.jaxws.support.JaxWsServiceConfiguration"/>
            <bean class="org.apache.cxf.aegis.databinding.AegisServiceConfiguration"/>
            <bean class="org.apache.cxf.service.factory.DefaultServiceConfiguration"/>
        </list>
    </property>
</bean>

<!-- JAX-RS -->
<jaxrs:server id="businessServiceabilityServiceJaxRsServer" address="/bs/rest">
    <jaxrs:serviceBeans>
        <ref bean="businessServiceabilityService"/>
    </jaxrs:serviceBeans>
</jaxrs:server>

<!-- JAX-WS -->
<jaxws:endpoint implementor="#businessServiceabilityService" address="/bs/soap">
    <jaxws:serviceFactory>
        <ref bean="jaxws-and-aegis-service-factory"/>
    </jaxws:serviceFactory>
</jaxws:endpoint>

SOAP サービスを登録するにはどうすればよいですか? web.xml でそれを行う可能性が見つかりませんでした。web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
     version="2.5">
<display-name></display-name>

<servlet>
    <servlet-name>CXFNonSpringJaxrsServlet</servlet-name>
    <servlet-class>org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet</servlet-class>
    <init-param>
        <param-name>jaxrs.providers</param-name>
        <param-value>XXXXXXXXXXXXXXXXXXXServiceImpl</param-value>
    </init-param>
    <init-param>
        <param-name>jaxrs.serviceClasses</param-name>
        <param-value>XXXXXXXXXXXXXXXXXXXServiceImpl</param-value>
    </init-param>
</servlet>

<servlet-mapping>
    <servlet-name>CXFNonSpringJaxrsServlet</servlet-name>
    <url-pattern>/cxf/rest/*</url-pattern>
</servlet-mapping>

前もって感謝します!V.

4

2 に答える 2

3

CXF を使用して Web サービスを作成する場合、Spring フレームワークはオプションです。次の jar のみが必要なため、パッケージ サイズが大幅に削減されます[CXF 2.7.3 使用時]

        commons-logging-1.1.1.jar
        cxf-2.7.3.jar
        httpasyncclient-4.0-beta3.jar
        httpclient-4.2.1.jar
        httpcore-4.2.2.jar
        httpcore-nio-4.2.2.jar
        neethi-3.0.2.jar
        wsdl4j-1.6.2.jar
        xmlschema-core-2.0.3.jar

以下は、JAX-WS サービスの例です。

http://www.javatips.net/blog/2012/10/cxf-soap-without-spring

以下は、JAX-RS サービスの例です。

http://www.javatips.net/blog/2012/10/cxf-rest-without-spring

于 2014-02-15T03:46:54.750 に答える
2

解決策を見つけました。

public class MyServiceServlet extends CXFNonSpringServlet {

private static final long serialVersionUID = 1L;

@Override
// Called at startup time to register this web service.
public void loadBus(ServletConfig servletConfig) throws ServletException {
    super.loadBus(servletConfig);

    Bus bus = getBus();
    BusFactory.setDefaultBus(bus);

    createFactoryBean(servletConfig);
}

private void createFactoryBean(ServletConfig servletConfig) {
    String address = servletConfig.getInitParameter("jaxws.address");
    String provider = servletConfig.getInitParameter("jaxws.provider");
    String serviceClass = servletConfig.getInitParameter("jaxws.serviceClass");

    JaxWsServerFactoryBean fb = new JaxWsServerFactoryBean();
    fb.setAddress(address);
    try {
        fb.setServiceBean(Class.forName(provider).newInstance());
    } catch (Exception e) {
        throw new RuntimeException("The class '"+provider+"' cannot be instantiated!", e);
    }
    try {
        fb.setServiceClass(Class.forName(serviceClass).getClass());
    } catch (ClassNotFoundException e) {
        throw new RuntimeException("The class '"+serviceClass+"' cannot be found!", e);
    } 
    fb.create();
}
}

そしてweb.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
     version="2.5">

<display-name></display-name>

<!-- CXF config -->
<servlet>
    <servlet-name>CXFNonSpringJaxrsServlet</servlet-name>
    <servlet-class>org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet</servlet-class>
    <init-param>
        <param-name>jaxrs.providers</param-name>
        <param-value>xxx.BusinessServiceabilityServiceImpl</param-value>
    </init-param>
    <init-param>
        <param-name>jaxrs.serviceClasses</param-name>
        <param-value>xxx.BusinessServiceabilityServiceImpl</param-value>
    </init-param>
</servlet>

<servlet>
    <servlet-name>MyServiceServlet</servlet-name>
    <servlet-class>xxx.MyServiceServlet</servlet-class>
    <init-param>
        <param-name>jaxws.address</param-name>
        <param-value>/almafa</param-value>
    </init-param>
    <init-param>
        <param-name>jaxws.serviceClass</param-name>
        <param-value>com.infoaxon.bpt.services.OACCostingServiceSoap</param-value>
    </init-param>
    <init-param>
        <param-name>jaxws.provider</param-name>
        <param-value>xxx.BusinessServiceabilityServiceImpl</param-value>
    </init-param>
</servlet>

<servlet-mapping>
    <servlet-name>CXFNonSpringJaxrsServlet</servlet-name>
    <url-pattern>/cxf/rest/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>MyServiceServlet</servlet-name>
    <url-pattern>/cxf/soap/*</url-pattern>
</servlet-mapping>

</web-app>
于 2012-05-30T16:29:52.107 に答える