最近要将一个thrift服务转为提webservices服务,提供给pad应用调用。

但是公司没有使用Spring的习惯,可基于CXFNonSpringServlet来实现

package com.cxfnospring.test;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;

import org.apache.cxf.Bus;
import org.apache.cxf.BusFactory;
import org.apache.cxf.frontend.ServerFactoryBean;
import org.apache.cxf.transport.servlet.CXFNonSpringServlet;

public class CXFNonSpringServletImpl extends CXFNonSpringServlet {

    private static final String SERVICE_SUFFIX = "";// "Facade";

    private static final long serialVersionUID = 8262880864551976903L;

    @Override
    public void loadBus(ServletConfig servletConfig) throws ServletException {
        super.loadBus(servletConfig);

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

        HelloWorldImpl helloworldImpl = new HelloWorldImpl();
        ServerFactoryBean svrFactory = new ServerFactoryBean();
        svrFactory.setServiceClass(HelloWorld.class);
        svrFactory.setAddress("/HelloWorld");
        svrFactory.setServiceBean(helloworldImpl);
        // svrFactory.getServiceFactory().setDataBinding(new
        // AegisDatabinding());
        svrFactory.create();

    }

    
}

例子:

package com.cxfnospring.test;

public interface HelloWorld {
    
    String sayHi(String text);

}
package com.cxfnospring.test;

public class HelloWorldImpl implements HelloWorld {

    public String sayHi(String text) {
        return "Hello " + text;
    }
}

然后修改Web.xml

<servlet>
        <servlet-name>CXFServlet</servlet-name>
        <servlet-class>
            com.cxfnospring.test.CXFNonSpringServletImpl
        </servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

maping 到/ws/*

发布到tomcat,ok!

 wsdl地址为http://ip:port/project_name/ws/fuctionname?wsdl

 

 

相关文章:

  • 2021-11-04
  • 2021-06-25
  • 2022-12-23
  • 2021-08-28
  • 2021-08-12
  • 2022-12-23
  • 2022-12-23
  • 2021-09-02
猜你喜欢
  • 2021-06-21
  • 2022-12-23
  • 2022-01-13
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案