生成SOAP Web服务示例会引发错误(Producing a SOAP web service example throws an error)

编程入门 行业动态 更新时间:2024-10-27 08:34:23
生成SOAP Web服务示例会引发错误(Producing a SOAP web service example throws an error)

来自世界各地的编码员

我已经在这个项目工作了一段时间,似乎无法找到我的问题。 这是我第一次使用肥皂和弹簧与我裸露。

这是我的XML架构

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://spring.io/guides/gs-producing-web-service" targetNamespace="http://spring.io/guides/gs-producing-web-service" elementFormDefault="qualified"> <xs:element name="getCountryRequest"> <xs:complexType> <xs:sequence> <xs:element name="name" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="getCountryResponse"> <xs:complexType> <xs:sequence> <xs:element name="country" type="tns:country"/> </xs:sequence> </xs:complexType> </xs:element> <xs:complexType name="country"> <xs:sequence> <xs:element name="name" type="xs:string"/> <xs:element name="population" type="xs:int"/> <xs:element name="capital" type="xs:string"/> <xs:element name="currency" type="tns:currency"/> </xs:sequence> </xs:complexType> <xs:simpleType name="currency"> <xs:restriction base="xs:string"> <xs:enumeration value="GBP"/> <xs:enumeration value="EUR"/> <xs:enumeration value="PLN"/> </xs:restriction> </xs:simpleType>

和我的终点

package hello; import org.springframework.boot.context.embedded.ServletRegistrationBean; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.io.ClassPathResource; import org.springframework.ws.config.annotation.EnableWs; import org.springframework.ws.config.annotation.WsConfigurerAdapter; import org.springframework.ws.transport.http.MessageDispatcherServlet; import org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition; import org.springframework.xml.xsd.SimpleXsdSchema; import org.springframework.xml.xsd.XsdSchema; @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/*"); } @Bean(name = "countries") public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema countriesSchema) { DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition(); wsdl11Definition.setPortTypeName("CountriesPort"); wsdl11Definition.setLocationUri("/ws"); wsdl11Definition.setTargetNamespace("http://spring.io/guides/gs-producing-web-service"); wsdl11Definition.setSchema(countriesSchema); return wsdl11Definition; } @Bean public XsdSchema countriesSchema() { return new SimpleXsdSchema(new ClassPathResource("countries.xsd")); } }

因此,每次我想执行我的程序时,都会出现错误读数

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'countries' defined in class path resource [hello/WebServiceConfig.class]: Unsatisfied dependency expressed through constructor argument with index 0 of type [org.springframework.xml.xsd.XsdSchema]: : Error creating bean with name 'countriesSchema' defined in class path resource [hello/WebServiceConfig.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: xsd 'class path resource [countries.xsd]' does not exist; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'countriesSchema' defined in class path resource [hello/WebServiceConfig.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: xsd 'class path resource [countries.xsd]' does not exist

我不明白为什么......

这里还有示例代码的链接(其余部分) https://spring.io/guides/gs/convert-jar-to-war/

所以,如果你能提供帮助,那将非常感激

问候

Here is my XML schema

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://spring.io/guides/gs-producing-web-service" targetNamespace="http://spring.io/guides/gs-producing-web-service" elementFormDefault="qualified"> <xs:element name="getCountryRequest"> <xs:complexType> <xs:sequence> <xs:element name="name" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="getCountryResponse"> <xs:complexType> <xs:sequence> <xs:element name="country" type="tns:country"/> </xs:sequence> </xs:complexType> </xs:element> <xs:complexType name="country"> <xs:sequence> <xs:element name="name" type="xs:string"/> <xs:element name="population" type="xs:int"/> <xs:element name="capital" type="xs:string"/> <xs:element name="currency" type="tns:currency"/> </xs:sequence> </xs:complexType> <xs:simpleType name="currency"> <xs:restriction base="xs:string"> <xs:enumeration value="GBP"/> <xs:enumeration value="EUR"/> <xs:enumeration value="PLN"/> </xs:restriction> </xs:simpleType>

and my EndPoint

package hello; import org.springframework.boot.context.embedded.ServletRegistrationBean; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.io.ClassPathResource; import org.springframework.ws.config.annotation.EnableWs; import org.springframework.ws.config.annotation.WsConfigurerAdapter; import org.springframework.ws.transport.http.MessageDispatcherServlet; import org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition; import org.springframework.xml.xsd.SimpleXsdSchema; import org.springframework.xml.xsd.XsdSchema; @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/*"); } @Bean(name = "countries") public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema countriesSchema) { DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition(); wsdl11Definition.setPortTypeName("CountriesPort"); wsdl11Definition.setLocationUri("/ws"); wsdl11Definition.setTargetNamespace("http://spring.io/guides/gs-producing-web-service"); wsdl11Definition.setSchema(countriesSchema); return wsdl11Definition; } @Bean public XsdSchema countriesSchema() { return new SimpleXsdSchema(new ClassPathResource("countries.xsd")); } }

So each time I want to execute my program I get an error reading

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'countries' defined in class path resource [hello/WebServiceConfig.class]: Unsatisfied dependency expressed through constructor argument with index 0 of type [org.springframework.xml.xsd.XsdSchema]: : Error creating bean with name 'countriesSchema' defined in class path resource [hello/WebServiceConfig.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: xsd 'class path resource [countries.xsd]' does not exist; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'countriesSchema' defined in class path resource [hello/WebServiceConfig.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: xsd 'class path resource [countries.xsd]' does not exist

and I have no idea why...

Also here is the link to the example code (The rest of it) https://spring.io/guides/gs/convert-jar-to-war/

最满意答案

您的代码失败,因为在类路径的根目录中找不到countries.xsd 。 您需要资源的类路径中指定绝对路径,或者将countries.xsd移动到类路径的根目录。

Your code is failing because countries.xsd cannot be found at the root of your classpath. You need to specify the absolute path in the classpath to your resource OR move your countries.xsd to the root of the classpath.

更多推荐

本文发布于:2023-04-29 08:30:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1335859.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:示例   错误   SOAP   Web   Producing

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!