我正在阅读有关Web服务的内容,并且正在从jax-ws源代码创建wsdl,我能够完美地创建wsdl,我在请求中有很多输入,我需要为特定字符串输入设置minOccurs和maxOccurs一个请求,我如何通过java代码来做到这一点。帮我解决这个问题
我的 wsdl 代码
<xs:element name="person"><xs:complexType><xs:sequence>
<xs:element name="employee" type="xs:string" minOccurs="1" maxOccurs="10"/>
<xs:element name="member" type="xs:string"/> </xs:sequence></xs:complexType></xs:element>
您无法通过类上的 jaxb 注释来定义此类限制。 您可以有 1 个,或者仅作为 maxoccurrency 不绑定
使用注释
@XmlElement(required = false)
,您将看到生成的minOccurs=0
。我正在使用 jaxb 2.4:
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>2.4</version>
对于原始类型(
int
、long
等),需要使用包装器(Integer
、Long
等)才能使其工作;对于 int
和 long
,将不会添加 minOccurs=0
。
插件配置如下:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>schemagen</id>
<phase>generate-resources</phase>
<goals>
<goal>schemagen</goal>
</goals>
</execution>
</executions>
<configuration>
<generateEpisode>true</generateEpisode>
<transformSchemas>
<transformSchema>
<uri>urn:com.example.model:data:1.0</uri>
<toPrefix>data</toPrefix>
<toFile>data.xsd</toFile>
</transformSchema>
<transformSchema>
<uri>urn:com.example.model:codes:1.0</uri>
<toPrefix>codes</toPrefix>
<toFile>codes.xsd</toFile>
</transformSchema>
</transformSchemas>
<sources>
<source>src/main/java/com/example/model/codes</source>
<source>src/main/java/com/example/model/data</source>
</sources>
<schemaSourceExcludeFilters>
<!-- [\\/] in the regex patterns matches both Windows and Unix path separators -->
<filter implementation="org.codehaus.mojo.jaxb2.shared.filters.pattern.PatternFileFilter">
<patternPrefix>.*[\\/]com[\\/]example[\\/]model[\\/]</patternPrefix>
<patterns>
<pattern>adapter[\\/].*</pattern>
<pattern>archive[\\/].*</pattern>
<pattern>data[\\/]number[\\/].*</pattern>
<pattern>data[\\/]event[\\/].*</pattern>
<pattern>exception[\\/].*</pattern>
</patterns>
</filter>
</schemaSourceExcludeFilters>
<verbose>true</verbose>
</configuration>
</plugin>
和 Maven 日志:
[INFO] --- jaxb2-maven-plugin:2.4:schemagen (schemagen) @ model ---
[INFO] Created EpisodePath [/home/westerngun/code/my-project/common/model/target/generated-resources/schemagen/META-INF/JAXB]: true
[INFO] Created EpisodePath [/home/westerngun/code/my-project/common/model/target/generated-resources/schemagen/META-INF/JAXB]: true
warning: Supported source version 'RELEASE_7' from annotation processor 'com.sun.tools.jxc.ap.SchemaGenerator' less than -source '1.8'
Note: Writing /home/westerngun/code/my-project/common/model/schema1.xsd
Note: Writing /home/westerngun/code/my-project/common/model/schema2.xsd
Note: Writing /home/westerngun/code/my-project/common/model/schema3.xsd
Note: Writing /home/westerngun/code/my-project/common/model/target/generated-resources/schemagen/META-INF/JAXB/episode_schemagen.xjb
Note: Writing /home/westerngun/code/my-project/common/model/target/generated-resources/schemagen/META-INF/JAXB/episode_schemagen.xjb
warning: Implicitly compiled files were not subject to annotation processing.
Use -proc:none to disable annotation processing or -implicit to specify a policy for implicit compilation.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
[INFO] XSD post-processing: Adding JavaDoc annotations in generated XSDs.
[INFO] Processing [278] java sources.
[INFO] XSD post-processing: Renaming and converting XSDs.
[WARNING] SimpleNamespaceResolver contained no localNamespaceURI; aborting rename.