服务端
项目结构
maven依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-spring-boot-starter-jaxws</artifactId>
<version>3.4.3</version>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.6.3</version>
</dependency>
application.properties配置
cxf.path=/ws
Spring Bean配置
package com.example.webservicedemo.config;
import cn.hutool.extra.spring.SpringUtil;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class BeanConfig {
@Bean
public SpringUtil springUtil() {
return new SpringUtil();
}
}
DTO
package com.example.webservicedemo.dto;
import lombok.Data;
@Data
public class UserDto {
private String name;
private Integer age;
private UserDto friend;
}
Endpoint
package com.example.webservicedemo.endpoint;
import org.springframework.stereotype.Service;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
@Service
@WebService
public class Hello {
@WebMethod
public String sayHello(@WebParam String name) {
return "hello," + name;
}
@WebM