maven
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.longzhu</groupId>
<artifactId>WbsClient</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>WbsClient</name>
<description>WbsClient</description>
<url/>
<licenses>
<license/>
</licenses>
<developers>
<developer/>
</developers>
<scm>
<connection/>
<developerConnection/>
<tag/>
<url/>
</scm>
<properties>
<java.version>1.8</java.version>
<cxf.version>3.5.0</cxf.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!--<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.7.4</version>
</dependency>-->
<!-- 服务端依赖 start -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-spring-boot-starter-jaxws</artifactId>
<version>${cxf.version}</version>
</dependency>
<!-- 服务端依赖 end -->
<!-- 客户端依赖 start -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>${cxf.version}</version>
</dependency>
<!-- 客户端依赖 end -->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
服务端代码
接口
package com.longzhu.longbootcxf.service;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
/**
* @AuThor WenHao
* @date 2024/7/9
*/
@WebService(targetNamespace = "http://service.longbootcxf.longzhu.com",name = "HelloService")
public interface HelloService {
@WebMethod
String sayHello(@WebParam(name = "name11") String name);
}
实现类
package com.longzhu.longbootcxf.service.impl;
import com.longzhu.longbootcxf.service.HelloService;
import org.springframework.stereotype.Service;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
/**
* @author WenHao
* @date 2024/7/11
*/
@WebService(serviceName = "hello",
targetNamespace= "http://service.longbootcxf.longzhu.com",
endpointInterface = "com.longzhu.longbootcxf.service.HelloService")
@Service
public class HelloServiceImpl implements HelloService {
/**
* @author WenHao
* @date 2024/7/11
* return String
*/
//@WebMethod
@Override
public String sayHello(/*@WebParam(name = "name") */String name) {
System.out.println("name = " + "hello " + name);
return "hello" + name;
}
}
配置类
package com.longzhu.longbootcxf.config;
import com.longzhu.longbootcxf.service.impl.HelloServiceImpl;
import org.apache.cxf.Bus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.xml.ws.Endpoint;
/**
* @author WenHao
* @date 2024/7/11
*/
@Configuration
public class CxfConfig {
@Autowired
private Bus bus;
@Autowired
private HelloServiceImpl helloService;
@Bean
public Endpoint helloServer(){
EndpointImpl endpoint = new EndpointImpl(bus, helloService);
endpoint.publish("/hello");
return endpoint;
}
}
|