springboot集成websevice

需要的依赖:

		        
			        org.springframework.boot
			        spring-boot-starter-web-services
		        
			
				org.apache.cxf
				cxf-rt-frontend-jaxws
				3.1.6
			
			
				org.apache.cxf
				cxf-rt-transports-http
				3.1.6
			
			
				org.apache.cxf
				cxf-spring-boot-starter-jaxws
				3.2.4
			
			
				org.hamcrest
				hamcrest-all
				1.3
				test
			
			
				wsdl4j
				wsdl4j
				1.6.3
			

service:

@WebService(name = "DemoService", // 暴露服务名称
targetNamespace = "http://service.prj.sharePlatform.hnykx.com"// 命名空间,一般是接口的包名倒序
)
public interface DemoService {
	@WebMethod
	@WebResult(name = "String",targetNamespace = "")
public String hello(@WebParam(name = "str")String str);

}

serviceimpl:

@WebService(serviceName = "DemoService", // 与接口中指定的name一致
targetNamespace = "http://service.prj.sharePlatform.hnykx.com", // 与接口中的命名空间一致,一般是接口的包名倒
endpointInterface = "com.hnykx.sharePlatform.prj.service.DemoService"// 接口地址
)
public class DemoServiceImpl implements DemoService {

@Override
public String hello(String str) {
	return "hello" + str;
}

}

CxfConfig:

@Configuration
public class CxfConfig {

   @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;
   }

}

springboot集成websevice_第1张图片

你可能感兴趣的:(springboot,webService)