简体   繁体   English

如何使用spring-ws记录未处理的异常

[英]How to log unhandled exceptions using spring-ws

spring web services (spring-ws) has a default SimpleSoapExceptionResolver which will return any unhandled exceptions to the client as a SOAP fault. Spring Web服务(spring-ws)具有默认的SimpleSoapExceptionResolver,它将作为SOAP错误返回所有未处理的异常给客户端。 This is good. 很好

However, i would also like it to log the exception on the server so we have visibility to support the service. 但是,我也希望它在服务器上记录异常,以便我们可以看到支持该服务的信息。

SimpleSoapExceptionResolver via AbstractEndpointExceptionResolver has a property that can be set to enable logging (setWarnLogCategory). 通过AbstractEndpointExceptionResolver的SimpleSoapExceptionResolver具有可以设置为启用日志记录的属性(setWarnLogCategory)。

How can i get a handle on the instance of SimpleSoapExceptionResolver that the framework creates in order to set the warnLogCategory property? 我如何获得框架创建的SimpleSoapExceptionResolver实例的句柄以设置warnLogCategory属性?

Thanks, Dan. 谢谢,丹。

The reference documentation says: 参考文档说:

Endpoint exception resolvers are automatically picked up by the MessageDispatcher, so no explicit configuration is necessary. 端点异常解析器由MessageDispatcher自动提取,因此不需要显式配置。

So just instantiate the class and set the property: 因此,只需实例化类并设置属性即可:

<bean id="exceptionResolver" class="org.springframework.ws.soap.server.endpoint.SimpleSoapExceptionResolver">
  <property name="warnLogCategory" value="com.mycompany.category"/>
</bean>

Here is one possibility, to use container injection to get a handle on it in a single use bean 这是一种可能,可以使用容器注入在一个一次性使用的bean中获得其句柄

There must be a way to do it without having to create java classes whole sole purpose is to configure a spring bean. 必须有一种方法而不必创建java类,唯一的目的是配置spring bean。

  @Named public class ConfigurationBean {

     @Inject SoapFaultAnnotationExceptionResolver resolver;

  @PostConstruct public void initialise() {
     resolver.setWarnLogCategory("Dingbats"); 
  }
} 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM