Spring集成:@ServiceActivator无效

时间:2016-07-15 13:18:57

标签: java spring spring-integration

我有以下课程:

@Configuration
public class SpringIntegrationTest {

    @Bean
    public SimpleWebServiceInboundGateway testInboundGateWay (){
        SimpleWebServiceInboundGateway simpleWebServiceInboundGateway = new SimpleWebServiceInboundGateway();
        simpleWebServiceInboundGateway.setRequestChannelName("testChannel");
        simpleWebServiceInboundGateway.setReplyChannelName("testChannel2");
        return simpleWebServiceInboundGateway;
    }

    @Bean
    public MessageChannel testChannel() {
        return new DirectChannel();
    }

    @Bean
    public MessageChannel testChannel2() {
        return new DirectChannel();
    }

    @ServiceActivator(inputChannel = "testChannel", outputChannel = "testChannel2")
    public DOMSource foo(DOMSource request) {
        System.out.println("asd");
        return request;
    }

    @Bean
    public EndpointMapping soapActionEndpointMapping(SimpleWebServiceInboundGateway testInboundGateWay ) {
        UriEndpointMapping uriEndpointMapping = new UriEndpointMapping();
        uriEndpointMapping.setUsePath(true);
        uriEndpointMapping.setEndpointMap(createEndpointMapping(testInboundGateWay ));
        return uriEndpointMapping;
    }

    private Map<String, Object> createEndpointMapping(SimpleWebServiceInboundGateway testInboundGateWay ) {
        Map<String, Object> endpointMap = new HashMap<>();
        endpointMap.put("/ws/test", testInboundGateWay );
        return endpointMap;
    }

}

即使很难服务激活者订阅&#34; testChannel&#34;,我收到以下消息:

  

o.s.i.w.SimpleWebServiceInboundGateway - 网关发生故障sendAndReceive:Dispatcher没有订阅者的频道&org.springframework.web.context.WebApplicationContext:/ MyProject restful API.testChannel&#39;。;嵌套异常是org.springframework.integration.MessageDispatchingException:Dispatcher没有订阅者

我做错了什么?

2 个答案:

答案 0 :(得分:4)

您需要将@EnableIntegration添加到其中一个配置类中。

答案 1 :(得分:0)

向testChannel添加调度程序可以解决此问题。