java 通过 Maven 的 CXF 2.7.x Woodstox 兼容性

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16903216/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-01 00:19:59  来源:igfitidea点击:

CXF 2.7.x Woodstox Compatibility via Maven

javaweb-servicescxfwoodstox

提问by Dmitry

In the CXF's documentation it is said that the 2.7.x version requires the Woodstox jars not under the 4.2.0 version to be available in the classpath.

在 CXF 的文档中,据说 2.7.x 版本要求不在 4.2.0 版本下的 Woodstox jar 在类路径中可用。

Can somebody, please, suggest Maven dependencies for Woodstox to work with CXF?

有人可以建议 Woodstox 的 Maven 依赖项与 CXF 一起使用吗?

The main problem is when I try to use the cxf's client, an exception "Cannot create a secure XMLInputFactory" is raised. According to different forums (for example), it is possible to use the "org.apache.cxf.stax.allowInsecureParser" system property to solve the problem, but it seems not a good way. So that maven dependencies are the way to go...

主要问题是当我尝试使用 cxf 的客户端时,会引发异常“无法创建安全的 XMLInputFactory”。根据不同的论坛(例如),可以使用“org.apache.cxf.stax.allowInsecureParser”系统属性来解决问题,但似乎不是一个好方法。所以maven依赖是要走的路......

Thanks in advance.

提前致谢。

采纳答案by Dmitry

Well, finally I've got a solution. First of all I'd like to thank StaxMan for a help.

好吧,我终于找到了解决方案。首先,我要感谢 StaxMan 的帮助。

My environment is: Weblogic 11g, CXF 2.7.5

我的环境是:Weblogic 11g,CXF 2.7.5

The problem is WLS already contains implementations for StAX API and xml parsers that is why an application doesn't see the Woodstox parser when using CXF.

问题是 WLS 已经包含 StAX API 和 xml 解析器的实现,这就是应用程序在使用 CXF 时看不到 Woodstox 解析器的原因。

Here is the pom.xml:

这是 pom.xml:

        <!-- CXF -->
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-api</artifactId>
        </dependency>

        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-frontend-jaxws</artifactId>
        </dependency>

        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-transports-http</artifactId>
        </dependency>

and the main part -- the weblogic-application.xml located in the resources/META-INF/ :

和主要部分——位于 resources/META-INF/ 中的 weblogic-application.xml :

    <prefer-application-packages>
        <package-name>com.ctc.wstx.*</package-name>
        <package-name>org.apache.*</package-name>
    </prefer-application-packages>

Be aware of the fact that if do so there may occure the "NoClassDefinition" errors. If so, please, add maven dependencies that contain missing classes.

请注意,如果这样做,可能会出现“NoClassDefinition”错误。如果是这样,请添加包含缺失类的 Maven 依赖项。

Hope this helps somebody.

希望这可以帮助某人。

回答by Neron

This worked for me without prefer-application-packages impl:

这对我有用,没有首选应用程序包实现:

<dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-frontend-jaxws</artifactId>
            <version>${cxf.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>com.sun.xml.bind</groupId>
                    <artifactId>jaxb-impl</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>com.sun.xml.bind</groupId>
            <artifactId>jaxb-impl</artifactId>
            <version>2.2.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-transports-http</artifactId>
            <version>${cxf.version}</version>
        </dependency>
        <!-- Jetty is needed if you're using the CXFServlet -->
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-transports-http-jetty</artifactId>
            <version>${cxf.version}</version>
        </dependency>

回答by Dmitry

The only way for now I can solve the problem is to add such lines in the spring's context:

现在我可以解决问题的唯一方法是在 spring 的上下文中添加这样的行:

<bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
    <property name="targetObject">
        <bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
            <property name="targetClass" value="java.lang.System" />
            <property name="targetMethod" value="getProperties" />
        </bean>
    </property>
    <property name="targetMethod" value="putAll" />
    <property name="arguments">
        <util:properties>
            <prop key="org.apache.cxf.stax.allowInsecureParser">true</prop>
        </util:properties>
    </property>
</bean>