使用xsd的spring boot创建soap服务,而不使用自动生成类

时间:2016-05-12 14:38:29

标签: java spring maven soap xsd

我是使用spring boot的初学者,我正在尝试将spring应用程序迁移到spring boot,并且在尝试使用xsd使用spring-ws创建soap服务时遇到了一些困难。

我的xsd看起来像这样:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema attributeFormDefault="unqualified" 
            elementFormDefault="unqualified" 
            targetNamespace="ro.orange.PegaWS" 
            xmlns:xs="http://www.w3.org/2001/XMLSchema" 
            xmlns:tns="ro.orange.PegaWS">

   <xs:element name="getStockDetailsRequest" type="tns:getStockDetailsRequest"/>
   <xs:element name="getStockDetailsResponse" type="tns:getStockDetailsResponse"/>
   <xs:complexType name="getStockDetailsRequest">
      <xs:sequence>
         <xs:element minOccurs="0" name="userData" type="tns:userData"/>
         <xs:element maxOccurs="unbounded" minOccurs="0" name="oaCodes" type="xs:string"/>
      </xs:sequence>
   </xs:complexType>
   <xs:complexType name="userData">
      <xs:sequence>
         <xs:element minOccurs="0" name="dealerCode" type="xs:string"/>
         <xs:element minOccurs="0" name="department" type="xs:string"/>
         <xs:element minOccurs="0" name="userName" type="xs:string"/>
      </xs:sequence>
   </xs:complexType>
   <xs:complexType name="getStockDetailsResponse">
      <xs:sequence>
          <xs:element name="name" type="xs:string"/>
      </xs:sequence>
   </xs:complexType>
</xs:schema>

我使用maven构建:

<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>orange.com</groupId>
  <artifactId>prstutorial</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.3.5.RELEASE</version>
    </parent>

  <name>prstutorial</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <java.version>1.8</java.version>
  </properties>

  <dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-ws</artifactId>
    </dependency>

    <dependency>
        <groupId>wsdl4j</groupId>
        <artifactId>wsdl4j</artifactId>
    </dependency>

    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
      <scope>test</scope>
    </dependency>

  </dependencies>

      <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>jaxb2-maven-plugin</artifactId>
                <version>1.6</version>
                <executions>
                    <execution>
                        <id>xjc</id>
                        <goals>
                            <goal>xjc</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <schemaDirectory>${project.basedir}/src/main/resources/META-INF/schema</schemaDirectory>
                    <outputDirectory>${project.basedir}/src/main/java</outputDirectory>
                    <clearOutputDir>false</clearOutputDir>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

我也在这里创建肥皂服务:

package ro.orange.acrm.proxy.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration;
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.web.servlet.DispatcherServlet;
import org.springframework.ws.config.annotation.EnableWs;
import org.springframework.ws.transport.http.MessageDispatcherServlet;
import org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition;
import org.springframework.ws.wsdl.wsdl11.Wsdl11Definition;
import org.springframework.xml.xsd.SimpleXsdSchema;
import org.springframework.xml.xsd.XsdSchema;

@EnableWs
@Configuration
public class WebServicesConfig {

    private static String SCHEMA_LOCATION = "META-INF/schema/stocks.xsd";

    @Value("${NRSSmartPadServiceEndPointWSDL}")
    private String nrsSmartPadService;

    @Bean
    public DispatcherServlet dispatcherServlet() {
        return new DispatcherServlet();
    }

    @Bean
    public ServletRegistrationBean dispatcherServletRegistration() {
        ServletRegistrationBean registration = new ServletRegistrationBean(dispatcherServlet(), "/rest/*");
        registration.setName(DispatcherServletAutoConfiguration.DEFAULT_DISPATCHER_SERVLET_REGISTRATION_BEAN_NAME);
        return registration;
    }

    @Bean
    public ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) {
        MessageDispatcherServlet servlet = new MessageDispatcherServlet();
        servlet.setApplicationContext(applicationContext);
        servlet.setTransformWsdlLocations(true);
        return new ServletRegistrationBean(servlet, "/*");
    }

    @Bean(name = "PegaWS")
    public Wsdl11Definition defaultWsdl11Definition() {
         DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
         wsdl11Definition.setPortTypeName("PegaWS");
         wsdl11Definition.setLocationUri("/PegaWS");
         wsdl11Definition.setTargetNamespace("ro.orange.PegaWS");
         wsdl11Definition.setSchema(countriesSchema());
         return wsdl11Definition;
    }

    @Bean
    public XsdSchema countriesSchema() {
        return new SimpleXsdSchema(new ClassPathResource(SCHEMA_LOCATION));
    }
}

Maven在包pegaws.orange.ro中自动生成我的类。但是我需要从当前应用程序重用我的类而不是创建新的类。

例如,它在包pegaws.orange.ro/UserData.java中创建了类,但我需要从包ro.orange.beans / UserData.java中重用我的类。

这可能,还是我需要接受自动生成的类?

谢谢。

0 个答案:

没有答案