springboot整合cxf

 

<dependency>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-starter-web-services</artifactId>
</dependency>

 <dependency>
     <groupId>org.apache.cxf</groupId>
     <artifactId>cxf-spring-boot-starter-jaxws</artifactId>
     <version>3.3.3</version>
</dependency>

服务端:

@WebService(targetNamespace = "http://acct.com")
public interface HelloWorld{
    @WebMethod
    @WebResult(name = "responseInfo")
    public String say(@WebParam(name = "requestInfo") String 
    requestInfo);
}
@Component
@WebService(serviceName="acctSoap",targetNamespace="http://acct.com",endpointInterface = "com.acct.webservice.HelloWorld")
public class HelloWorldImpl implements HelloWorld{
      @Override
    public String say(String RequestInfo) {
         System.out.println(RequestInfo);
    }
}

发布服务:

@Configuration
public class CxfConfigServicee {
     @Autowired
     private HelloWorld helloWorld;
     @Bean
     public ServletRegistrationBean getDispatcherServlet() {
         return new ServletRegistrationBean(new CXFServlet(), "/cxf/*");// 发布服务名称 localhost:8080/cxf
     }

     @Bean(name = Bus.DEFAULT_BUS_ID)
     public SpringBus springBus() {
         return new SpringBus();
     }

     @Bean
     public Endpoint helloWorld() {
         EndpointImpl endpoint = new EndpointImpl(springBus(),helloWorld);
         endpoint.publish("/helloWorld"); // 接口访问地址
         endpoint.getInInterceptors().add(new ServerNameSpaceInterceptor());//忽略命名空间
         return endpoint;
     }
}

客户端:

  public static void main(String[] args) throws Exception{
        JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
        Client client = dcf.createClient("http://localhost:8080/cxf/helloWorld?wsdl");
        Object[] objects;
        String str="你好";
        objects = client.invoke("say", str);
        System.out.println(objects[0].toString());
    }

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值