springboot中集成webservice

1.pom中引入

   <dependency>
		<groupId>org.apache.cxf</groupId>
		<artifactId>cxf-rt-frontend-jaxws</artifactId>
		<version>3.2.6</version>
	</dependency>
	<dependency>
		<groupId>org.apache.cxf</groupId>
		<artifactId>cxf-rt-transports-http</artifactId>
		<version>3.2.6</version>
	</dependency>
本人遇到了很大的坑
查阅网上资料后发现 spring boot 1.4 版本对应cxf-spring-boot-starter-jaxws   3.1.X  版本

                                    spring boot 1.5 版本对应cxf-spring-boot-starter-jaxws   3.2.X  版本

2.CxfConfig.java

package com.sdyy.springboot.config;

import javax.xml.ws.Endpoint;

import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.transport.servlet.CXFServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.sdyy.biz.example.DemoService;
import com.sdyy.biz.example.DemoServiceImpl;

@Configuration
public class CxfConfig {
@Bean
public ServletRegistrationBean disServlet() {
return new ServletRegistrationBean(new CXFServlet(),"/demo/*");
}

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

@Bean
public DemoService demoService() {
    return new DemoServiceImpl();
}

@Bean
public Endpoint endpoint() {
    EndpointImpl endpoint = new EndpointImpl(springBus(), demoService());
    endpoint.publish("/api");
    return endpoint;
}

}

3.DemoService .java
package com.sdyy.biz.example;

import javax.jws.WebService;

@WebService
public interface DemoService {

public String sayHello(String user);

}

4.DemoServiceImpl .java
package com.sdyy.biz.example;

import java.util.Date;

import javax.jws.WebService;
@WebService(serviceName=“DemoService”,//对外发布的服务名
targetNamespace=“http://sdyy.biz.example.com”,//指定你想要的名称空间,通常使用使用包名反转
endpointInterface=“com.sdyy.biz.example.DemoService”)//服务接口全路径, 指定做SEI(Service EndPoint Interface)服务端点接口br/>@Component
public class DemoServiceImpl implements DemoService {

 @Override
    public String sayHello(String user) {
        return user+",现在时间:"+"("+new Date()+")";
    }

}

5.浏览器输入 http://localhost:8180/CIRMS/demo/api?wsdl

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值