【问题标题】:Spring Async method not working with EndPointSpring Async 方法不适用于 EndPoint
【发布时间】:2018-09-23 13:08:15
【问题描述】:

我的 Async 实现无法正常工作,但我似乎已正确完成所有操作。

我正在从我的 EndPoint 类中调用我的异步方法。

请查看下面的代码并帮助我解决问题。

我的 EndPoint 类如下:

@Endpoint
public class EndpointDummy {

    private static final String TARGET_NAMESPACE = "http://www.abc.xyz.com/GetAcctInfo";

    @Autowired
    private DummyService service;

    @PayloadRoot(localPart = "GetAcctInfoRq", namespace = TARGET_NAMESPACE)
    public @ResponsePayload GetAcctInfoRs handleRequest(@RequestPayload GetAcctInfoRq request, MessageContext messageContext) throws JAXBException, TransformerException {

        /*****************************************************************
        * Call the handler function
        * This handler function is asynchronous
        *****************************************************************/
        service.handleRequest();

        /*****************************************************************
        * Send response back
        *****************************************************************/
        SaajSoapMessage soapResponse = (SaajSoapMessage) messageContext.getResponse();
        SoapHeader respheader = soapResponse.getSoapHeader(); 

        MsgHdrRs msgHdrRs = new MsgHdrRs();
        JAXBContext jaxbContext = JAXBContext.newInstance(MsgHdrRs.class);
        jaxbContext.createMarshaller().marshal(msgHdrRs, respheader.getResult());

        GetAcctInfoRs response = new GetAcctInfoRs();
        return response;
    }
}

如上所示,我的 EndPoint 类调用了 DummyService 方法 handleRequest。

Dummy Service 类使用@Service 进行注解,handRequest 方法使用@Async 进行注解,如下所示:

@Service
public class DummyService {

    private Logger logger = Logger.getLogger(DummyService.class);

    @Async("taskExecutorServiceImpl")
    public void handleRequest() {

        logger.info("DummyService: 1");

        try {
            Thread.sleep(20000);
        } catch (InterruptedException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

        logger.info("DummyService: 2");
    }

}

我还定义了我的配置类如下:

@Configuration
@EnableAsync
public class ThreadConfig {

    @Bean(name = "taskExecutorServiceImpl")
    public ThreadPoolTaskExecutor specificTaskExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.initialize();
        return executor;
    }
}

请帮助我解决问题。我是 Spring 框架的新手,希望能在这方面提供任何帮助。

谢谢

【问题讨论】:

    标签: java spring web-services asynchronous spring-ws


    【解决方案1】:

    问题已解决,与上述代码无关。 问题出在配置文件中,与上面正确的代码无关。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-03-26
      • 2020-11-28
      • 2018-11-09
      • 2017-10-19
      • 1970-01-01
      • 2018-05-27
      • 2021-05-04
      • 2021-07-03
      相关资源
      最近更新 更多