编译 WSDL 文件时出现错误/警告 - 但生成的 Java 源代码正常 -Java17 spring boot 3.0

问题描述 投票:0回答:1

我的要求 spring boot 3.0 Java 17。我的代码使用 jaxb2 插件适用于 java 1.8 spring boot 2.7.11。我已将插件更新为 jaxb30-maven-plugin。自动生成的java代码就可以了。构建成功。但在构建控制台中我们可以发现以下错误。

[错误]解析模式时出错。Location [ file:.wsdl{11,51}].org.xml.sax.SAXParseException:s4s-elt-schema-ns:元素“definitions”的命名空间必须是来自模式命名空间“http://www.w3.org/2001/XMLSchema”

Error:

[INFO] --- jaxb30-maven-plugin:0.15.0:generate (default) @ ---
[INFO] Sources are not up-to-date, XJC will be executed.
[ERROR] Error while parsing schema(s).Location [ file:.wsdl{11,51}].
org.xml.sax.SAXParseException: s4s-elt-schema-ns: The namespace of element 'definitions' must be from the schema namespace, 'http://www.w3.org/2001/XMLSchema'.
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException (ErrorHandlerWrapper.java:204)
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error (ErrorHandlerWrapper.java:135)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError (XMLErrorReporter.java:396)
    at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.reportSchemaErr (XSDHandler.java:4254)
    at com.sun.org.apache.xerces.internal.impl.xs.traversers.


[ERROR] Error while parsing schema(s).Location [ file:.wsdl{11,51}].
org.xml.sax.SAXParseException: schema_reference.4: Failed to read schema document '.wsdl', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException (ErrorHandlerWrapper.java:204)
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error (ErrorHandlerWrapper.java:135)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError (XMLErrorReporter.java:396)
    at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.reportSchemaErr (XSDHandler.java:4254)
    at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.reportSchemaError (XSDHandler.java:4237)
    at com.sun.org.apache.xerces.internal.impl.xs.traversers.XSDHandler.constructTrees (XSDHandler.java:826)
    at com.sun.org.apache



pom:
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"
    xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.1.0</version>
        <relativePath />
        <!--lookup parent from repository -->
    </parent>
    <groupId>name</groupId>
    <artifactId>name</artifactId>
    <version>xxxxx.0000</version>
    <packaging>jar</packaging>
    <name>xxxxxxxx</name>
    <description>BW Spring Boot</description>
    <properties>
        <unitTests>Jenkins</unitTests>
        <javaVersion>17</javaVersion>
        <maven.compiler.source>${javaVersion}</maven.compiler.source>
        <maven.compiler.target>${javaVersion}</maven.compiler.target>
        <resourcePath>${project.basedir}/src/main/resources</resourcePath>
        <resPath>./src/main/resources</resPath>
        <libPath>${project.basedir}/src/main/lib</libPath>
        <ZKM_HOME>${project.basedir}/tools</ZKM_HOME>
        <testResourcePath>${project.basedir}/src/test/resources</testResourcePath>
    </properties>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.apache.commons</groupId>
                <artifactId>commons-text</artifactId>
                <optional>true</optional>
            </dependency>           
        </dependencies>
    </dependencyManagement>
    <dependencies>
        <!-- https://mvnrepository.com/artifact/org.apache.lucene/lucene-core -->
        <dependency>
            <groupId>org.apache.lucene</groupId>
            <artifactId>lucene-core</artifactId>
            <version>3.0.2</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/commons-codec/commons-codec -->
        <dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-logging</artifactId>
                </exclusion>
                <exclusion>
             <groupId>org.yaml</groupId>
                <artifactId>snakeyaml</artifactId>
         </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web-services</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>6.1.6.Final</version>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-spring-boot-starter-jaxws</artifactId>  
            <version>3.4.10</version>       
        </dependency> 

        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-codegen-plugin</artifactId>
            <version>3.4.10</version>
            <exclusions>
                <exclusion>
                    <groupId>commons-io</groupId>
                    <artifactId>commons-io</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.apache.commons</groupId>
                    <artifactId>commons-compress</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.ws</groupId>
            <artifactId>spring-ws-support</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.5.14</version>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-core</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-api</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
        </dependency>
        <dependency>
            <groupId>org.owasp.encoder</groupId>
            <artifactId>encoder</artifactId>
            <version>1.2.3</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>

            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <includeSystemScope>true</includeSystemScope>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <groups>${unitTests}</groups>
                    <argLine>-Djava.library.path=${testResourcePath}
                        -Dbwiabsolute.properties.file=${testResourcePath}/xxxxxxxxx.properties</argLine>
                    <additionalClasspathElements>
                        <additionalClasspathElement>${libPath}/bwint10.jar</additionalClasspathElement>
                        <additionalClasspathElement>${testResourcePath}/</additionalClasspathElement>
                    </additionalClasspathElements>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <debug>true</debug>
                    <debuglevel>lines,vars,source</debuglevel>
                    <source>${javaVersion}</source>
                    <target>${javaVersion}</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>com.evolvedbinary.maven.jvnet</groupId>
                <artifactId>jaxb30-maven-plugin</artifactId>
                <version>0.15.0</version>
                <dependencies>
                    <dependency>
                        <groupId>org.glassfish.jaxb</groupId>
                        <artifactId>jaxb-runtime</artifactId>
                        <version>2.3.1</version>
                     </dependency>
                </dependencies>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <schemaDirectory>${resourcePath}/wsdl/</schemaDirectory>
                    <schemaIncludes>
                        <include>*.wsdl</include>
                    </schemaIncludes>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jarsigner-plugin</artifactId>
                <version>3.0.0</version>
                <executions>
                    <execution>
                        <id>sign</id>
                        <goals>
                            <goal>sign</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <keystore>tools/xxxxx.pfx</keystore>
                    <alias>1</alias>
                    <storepass>xxxx*</storepass>
                    <keypass>xxxx*</keypass>
                    <arguments>
                        <argument>-tsa</argument>
                        <argument>http://timestamp.digicert.com</argument>
                    </arguments>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <profiles>
        
        <profile>
            <id>production</id>
            <build>
                <finalName>xxxxxxx-${version}</finalName>

                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <configuration>
                            <debug>false</debug>
                            <debuglevel>none</debuglevel>
                            <source>${javaVersion}</source>
                            <target>${javaVersion}</target>
                        </configuration>
                    </plugin>
                </plugins>

                <resources>
                    <resource>
                        <directory>${resPath}</directory>
                        <filtering>true</filtering>
                        <excludes>
                            <exclude>**/xxxxxx.properties</exclude>
                            <exclude>**/*.txt</exclude>
                            <exclude>**/log*.xml</exclude>
                            <exclude>**/*.dll</exclude>
                            <exclude>cert/**</exclude>
                            <exclude>certs/**</exclude>
                        </excludes>
                    </resource>
                </resources>
            </build>
        </profile>

        <profile>
            <id>integration</id>
            <properties>
                <java.version>${javaVersion}</java.version>
                <unitTests>Integration</unitTests>
            </properties>
        </profile>

    </profiles>
</project>
spring-boot jaxb wsdl java-17
1个回答
0
投票

我也遇到过类似的问题并找到了解决方案。似乎在某些情况下,XJC 处理器应该注意到它解析 WSDL 而不是简单的模式。只需在您的插件配置中设置它即可:

        <plugin>
            <groupId>com.evolvedbinary.maven.jvnet</groupId>
            <artifactId>jaxb30-maven-plugin</artifactId>
            <version>0.15.0</version>
            ...
            <configuration>
                ...
                <schemaLanguage>wsdl</schemaLanguage>
            </configuration>
        </plugin>
© www.soinside.com 2019 - 2024. All rights reserved.