스프링 부트에서 WSDL을 사용하는 방법
클라이언트가 제공한 WSDL과 스키마 파일을 가지고 있습니다.이 WSDL 파일을 사용하여 Spring-boot SOAP 웹 서비스를 생성해야 합니다.구글에서 검색하면 스프링으로 wsdl을 자동 생성해 줍니다.WSDL을 사용하여 SOAP 서비스를 생성하려면 어떻게 해야 합니까?
다음은 기존 wsdl을 Spring-W 및 Spring-boot와 함께 사용하기 위한 일반적인 절차입니다.
설정 클래스
@EnableWs
@Configuration
public class WebServiceConfig extends WsConfigurerAdapter {
@Bean
public ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) {
MessageDispatcherServlet servlet = new MessageDispatcherServlet();
servlet.setApplicationContext(applicationContext);
servlet.setTransformWsdlLocations(true);
return new ServletRegistrationBean(servlet, "/ws/*");
}
//http://localhost:8080/ws/services.wsdl --bean name is set to 'services'
@Bean(name = "services")
public Wsdl11Definition defaultWsdl11Definition() {
SimpleWsdl11Definition wsdl11Definition = new SimpleWsdl11Definition();
wsdl11Definition.setWsdl(new ClassPathResource("/schema/MyWsdl.wsdl")); //your wsdl location
return wsdl11Definition;
}
}
- pom.xml에서 'jaxb2-maven-plugin' 플러그인을 사용하여 wsdl에서 클래스를 생성합니다.
- Spring-WS에서는 사용자가 직접 엔드포인트를 작성해야 합니다.엔드포인트에 대한 코드가 생성되지 않았습니다.쓰기 쉽다.봄 웹사이트에서 튜토리얼/가이드를 따라 할 수 있습니다.
WSDL 파일에서 시작하여 Spring Boot을 사용하는 웹 서비스에는 여러 가지 옵션이 있습니다.일반적으로 Java 클래스는 WSDL 정의에서 생성됩니다.이를 지원하는 JAXB Maven 플러그인이 다수 있습니다.
또한 스프링 부트를 사용할 때는 스프링 부트스타터를 사용하여 필요한 의존관계를 자동으로 관리해야 합니다.
를 Spring Web 와 .maven-jaxb2-plugin
플러그 인.Spring-WS를 사용하여 WSDL 파일부터 시작하여 소비자와 프로바이더 모두를 위한 단계별 튜토리얼을 만들었습니다.
다른 으로는 Apache 프레임워크를 Apache CXF와 이 있습니다.cxf-codegen-plugin
플러그 인.CXF에는 CXF Spring Boot Starter라는 자체 사양도 포함되어 있습니다.cxf-spring-boot-starter-jaxws
시작하기 위해 CXF 스타터를 Spring Boot과 조합하여 WSDL 파일에서 시작하는 웹 서비스를 작성하는 예를 정리했습니다.
가장 쉬운 방법은 cxf-spring-boot-starter encluse를 사용하는 것입니다.Maven 플러그인으로 wsdl과 스키마 파일에서 필요한 모든 것을 생성할 수 있습니다.다음은 완전한 예입니다.https://github.com/codecentric/spring-samples/tree/master/cxf-boot-simple
pom.xml
& 파일을 wsdl에 만 하면 됩니다.src/main/resources
그리고 넌 거의 다 했어.다음은 pom.xml의 완전한 예를 제시하겠습니다.
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>de.codecentric.soap</groupId>
<artifactId>cxf-boot-simple</artifactId>
<version>2.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>cxf-boot-simple</name>
<description>Demo project for using Spring Boot Starter CXF</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.2.RELEASE</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>cxf-spring-boot-starter</artifactId>
<version>2.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>de.codecentric</groupId>
<artifactId>cxf-spring-boot-starter-maven-plugin</artifactId>
<version>2.0.0.RELEASE</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
패키지에 WebServiceConfiguration Java 클래스를 만들 수 있습니다.
@EnableWs
@Configuration
public class WebServiceConfig extends WsConfigurerAdapter {
@Bean
public ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) {
MessageDispatcherServlet servlet = new MessageDispatcherServlet();
servlet.setApplicationContext(applicationContext);
servlet.setTransformWsdlLocations(true);
return new ServletRegistrationBean(servlet, "/ProjectName/*");
}
@Bean(name = "wsdlname")
public DefaultWsdl11Definition defaultWsdl11Definition (XsdSchema cityRequestSchema) {
DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
wsdl11Definition.setRequestSuffix("ByCountry");
wsdl11Definition.setResponseSuffix("City");
wsdl11Definition.setPortTypeName("Hotelport");
wsdl11Definition.setLocationUri("/ProjectName");
wsdl11Definition.setTargetNamespace("http://spring.io/guides/gs-producing-web-service");
wsdl11Definition.setSchema(cityRequestSchema);
return wsdl11Definition;
}
@Bean
public XsdSchema cityRequestSchema() {
return new SimpleXsdSchema(new ClassPathResource("CityRequest.xsd"));
}
스프링 부트 앱으로 실행한 후...그런 다음 이 URL을 브라우저에 복사 붙여넣습니다.http://localhost:8080/ProjectName/wsdlname.wsdl
주의: localhost: 8080을 사용하여 Tomcat 포트로 대체
먼저 요청 및 응답에 대한 XSD 정의를 정의합니다.
그런 다음 엔드포인트 구성.(예: Bean 클래스 및 컨트롤러 클래스 생성)
그런 다음 요청을 수신하도록 메시지 디스패처 서블릿을 설정합니다.
그런 다음 wsdl4j 의존관계를 pom.xml에 추가합니다.
그런 다음 다음과 같이 웹 서비스 구성 클래스를 추가합니다.
@Bean(name = "students") public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema studentsSchema) { DefaultWsdl11Definition definition = new DefaultWsdl11Definition(); definition.setPortTypeName("StudentPort"); definition.setTargetNamespace("http://in28minutes.com/students"); definition.setLocationUri("/ws"); definition.setSchema(studentsSchema); return definition; } @Bean public XsdSchema studentsSchema() { return new SimpleXsdSchema(new ClassPathResource("student-details.xsd")); }
그런 다음 스프링 부트를 시작하고 wsdl URL에 액세스하면 wsdl 링크를 볼 수 있습니다.상세한 것에 대하여는, 이 블로그[1]를 참조해 주세요.
[1] https://dzone.com/articles/creating-a-soap-web-service-with-spring-boot-start
언급URL : https://stackoverflow.com/questions/33773346/how-to-use-wsdl-with-spring-boot
'programing' 카테고리의 다른 글
Android에서의 JSON 오브젝트 전송 및 해석 (0) | 2023.03.25 |
---|---|
jq가 대시와 번호가 있는 태그 이름에서 작동하지 않습니다. (0) | 2023.03.25 |
MUI - 컴포넌트를 중앙/오른쪽에 정렬하는 방법 (0) | 2023.03.25 |
JSON의 올바른 MIME 유형은 무엇입니까? (0) | 2023.03.25 |
확인란이 angularjs의 스코프에 바인딩되지 않음 (0) | 2023.03.20 |