You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Boot 3中如何关闭控制台的SAXException日志输出

问题:如何关闭Axis框架抛出的SAXException栈日志输出?

环境与依赖

使用Spring Boot v3.1.1 + JAVA 17开发后端服务,通过以下JAX-RPC依赖与内部服务通信:

implementation 'wsdl4j:wsdl4j:1.6.3'
implementation 'org.apache.axis:axis:1.4'
implementation 'org.apache.axis:axis-jaxrpc:1.4'
implementation 'org.codehaus.woodstox:stax2-api:4.2'

问题现象

开发阶段无异常,流程正常,但生产环境中org.xml.sax.SAXException导致日志体积持续增大,异常日志片段如下:

06-Jul-2023 04:00PM ERROR 1 --- [nio-8080-exec-2] o.a.a.c.Call                             : Exception:

org.xml.sax.SAXException: Bad types (class java.util.HashMap -> class com.lorem.ws.model.domain.customer.Contract)
    at org.apache.axis.message.RPCHandler.onStartChild(RPCHandler.java:286) ~[axis-1.4.jar!/:?]
    at org.apache.axis.encoding.DeserializationContext.startElement(DeserializationContext.java:1035) ~[axis-1.4.jar!/:?]
    at org.apache.axis.message.SAX2EventRecorder.replay(SAX2EventRecorder.java:165) ~[axis-1.4.jar!/:?]
    at org.apache.axis.message.MessageElement.publishToHandler(MessageElement.java:1141) ~[axis-1.4.jar!/:?]
    at org.apache.axis.message.RPCElement.deserialize(RPCElement.java:236) ~[axis-1.4.jar!/:?]
    at org.apache.axis.message.RPCElement.getParams(RPCElement.java:384) ~[axis-1.4.jar!/:?]
    at org.apache.axis.client.Call.invoke(Call.java:2467) ~[axis-1.4.jar!/:?]
    at org.apache.axis.client.Call.invoke(Call.java:2366) ~[axis-1.4.jar!/:?]
    at org.apache.axis.client.Call.invoke(Call.java:1812) ~[axis-1.4.jar!/:?]
    at org.apache.axis.client.AxisClientProxy.invoke(AxisClientProxy.java:163) ~[axis-1.4.jar!/:?]
    at jdk.proxy2.$Proxy112.getNetBalance(Unknown Source) ~[?:?]
    at jdk.internal.reflect.GeneratedMethodAccessor30.invoke(Unknown Source) ~[?:?]
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
    at java.lang.reflect.Method.invoke(Method.java:568) ~[axis-1.4.jar!/:?]
    at org.springframework.remoting.rmi.RmiClientInterceptorUtils.doInvoke(RmiClientInterceptorUtils.java:101) ~[spring-remoting-1.2.9.jar!/:1.2.9]
    at org.springframework.remoting.rmi.RmiClientInterceptorUtils.invoke(RmiClientInterceptorUtils.java:74) ~[spring-remoting-1.2.9.jar!/:1.2.9]
    at org.springframework.remoting.jaxrpc.JaxRpcPortClientInterceptor.invoke(JaxRpcPortClientInterceptor.java:504) ~[spring-remoting-1.2.9.jar!/:1.2.9]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184) ~[spring-aop-6.0.10.jar!/:6.0.10]
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:244) ~[spring-aop-6.0.10.jar!/:6.0.10]
    at jdk.proxy2.$Proxy113.getNetBalance(Unknown Source) ~[?:?]

注:仅粘贴异常开头部分,完整信息非常冗长。

当前日志配置

生产环境日志配置:

logging.level.root=error

相关代码

引发问题的方法(最初版本):

private void myCustomFunction(String value) {
    try {
        Balance[] balances = service.getNetBalance(value);
    } catch (Exception ignored) {}
}

getNetBalance方法会抛出RemoteException,无需处理该异常。

修改后尝试捕获RemoteException并自定义日志:

private void myCustomFunction(String value) {
    try {
        Balance[] balances = service.getNetBalance(value);
    } catch (RemoteException e) {
        log.error(e.getMessage())
    }
}

修改后能看到自定义日志,但org.xml.sax.SAXException的栈日志仍会输出,占用大量日志空间。

排查与尝试

曾尝试添加日志配置关闭相关输出,但未解决问题:

logging.level.org.xml.sax=off

经排查,抛出org.xml.sax.SAXException: Bad types的是org.apache.axis.message包下的RPCHandler类,相关代码片段:

if (null != xsiClass  && !JavaUtils.isConvertable(xsiClass, destClass)) {
           throw new SAXException("Bad types (" +
                                  xsiClass + " -> " + destClass + ")");
}

核心诉求

如何关闭该SAXException的栈日志输出,避免其打印到控制台?


内容的提问来源于stack exchange,提问作者RRGT19

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.16 20:14:53