在WS SoapFault中添加细节:不使用我的自定义ExceptionResolver

Eri*_*ria 3 spring spring-ws spring-boot

我正在使用Spring Boot(1.2.4.RELEASE)构建一个Web服务,我对这个框架很新.特别是,我正在尝试在抛出异常时自定义SoapFault内容(添加"detail"标记).

我按照这篇文章这样做:http://www.stevideter.com/2009/02/18/of-exceptionresolvers-and-xmlbeans/

这是我的例外:

package foo.bar.exception;

import org.springframework.ws.soap.server.endpoint.annotation.FaultCode;
import org.springframework.ws.soap.server.endpoint.annotation.SoapFault;

@SoapFault(faultCode = FaultCode.SERVER)
public class ServiceException extends Exception {

    private static final long serialVersionUID = -1804604596179996724L;

    private String tempFaultDetail;

    public ServiceException(){
        super("ServiceException");
    }

    public ServiceException(String message) {
        super(message);
    }

    public ServiceException(String message, Throwable cause) {
        super(message, cause);
    }

    public ServiceException(String message, Throwable cause, String fautDetail) {
        super(message, cause);
        setTempFaultDetail( fautDetail );
    }


    public String getTempFaultDetail() {
        return tempFaultDetail;
    }

    public void setTempFaultDetail(String tempFaultDetail) {
        this.tempFaultDetail = tempFaultDetail;
    }       
}
Run Code Online (Sandbox Code Playgroud)

这是我的beans.xml(我尝试用Java配置和注释来做,但我不确定我做得对,所以我备份到XML bean声明):

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

    <bean id="exceptionResolver"
        class="foo.bar.ws.DetailSoapFaultDefinitionExceptionResolver">
        <property name="defaultFault" value="SERVER" />
        <property name="exceptionMappings">
            <value>
                foo.bar.exception.ServiceException=SERVER,FaultMsg
            </value>
        </property>
        <property name="order" value="1" />
    </bean>
</beans>
Run Code Online (Sandbox Code Playgroud)

我写的自定义类重写了SoapFaultAnnotationExceptionResolver(起初我扩展了SoapFaultMappingExceptionResolver,如上文所述):

package foo.bar.ws;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import org.springframework.ws.soap.SoapFault;
import org.springframework.ws.soap.server.endpoint.SoapFaultAnnotationExceptionResolver;

@Component
public class DetailSoapFaultDefinitionExceptionResolver extends
        SoapFaultAnnotationExceptionResolver {

    public final static Logger logger = Logger.getLogger( DetailSoapFaultDefinitionExceptionResolver.class );

    public DetailSoapFaultDefinitionExceptionResolver() {
        super();
        // TODO Auto-generated constructor stub
    }

    @Override
    protected void customizeFault(Object endpoint, Exception ex, SoapFault fault) {
        logger.debug("TEST OK !");
    }

}
Run Code Online (Sandbox Code Playgroud)

但是当我在端点中抛出ServiceException时,自定义类的customizeFault方法永远不会被命中.并且有充分的理由,用作异常处理程序的类仍然是SoapFaultAnnotationExceptionResolver而不是我的......

有人看到解释吗?

已经看过了:

Eri*_*ria 7

像往常一样,我在网上发布一小时后就解决了我的问题.我应该早点做完!

我试图覆盖的bean名称/ id不正确.扫描了大量的org.springframework.beans调试日志后,我发现正确的bean名称是soapFaultAnnotationExceptionResolver.

我还设法转换Java格式的配置:

package foo.bar.ws;

// Skipping imports...

/**
 * WS configuration and WSDL definition
 */
@EnableWs
@Configuration
public class WebServiceConfig extends WsConfigurerAdapter {

    public final static Logger logger = Logger.getLogger( WebServiceConfig.class );

    // Skipping other bean declarations...

    @Bean(name = "soapFaultAnnotationExceptionResolver")
    public DetailSoapFaultDefinitionExceptionResolver exceptionResolver( ApplicationContext applicationContext ){
        DetailSoapFaultDefinitionExceptionResolver exceptionResolver = new DetailSoapFaultDefinitionExceptionResolver();

        SoapFaultDefinition soapFaultDefinition = new SoapFaultDefinition();
        soapFaultDefinition.setFaultCode( SoapFaultDefinition.SERVER );
        exceptionResolver.setDefaultFault( soapFaultDefinition );

        return exceptionResolver;
    }

}
Run Code Online (Sandbox Code Playgroud)