2016-10-14 3 views
1

경로 목록을 기반으로 만들어야하는 여러 HTTP 끝점을 실행하려고합니다. 여러 동적 HTTP 끝점

현재 나는 1 개의 엔드 포인트 만들 수 있어요 :

@MessagingGateway(defaultRequestChannel = "requestChannel") 
public interface Gateway { 
    String sendReceive(String in); 
} 

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

@Bean 
public IntegrationFlow flow() { 
    return IntegrationFlows.from("requestChannel").transform(new ObjectToStringTransformer()) 
      .handle(new MyHandle()) 
      .get(); 
} 

@Bean 
public HttpRequestHandlingMessagingGateway httpGate() { 
    HttpRequestHandlingMessagingGateway gateway = new HttpRequestHandlingMessagingGateway(true); 
    RequestMapping mapping = new RequestMapping(); 
    mapping.setMethods(HttpMethod.POST); 
    mapping.setPathPatterns("/path"); 
    gateway.setRequestMapping(mapping); 
    gateway.setRequestChannel(requestChannel()); 
    gateway.setRequestPayloadType(byte[].class); 
    return gateway; 
} 

을하지만 난 이런 식으로 뭔가를해야만하고 싶지 :

@Autowired 
List<String> paths; 

@PostConstruct 
public void createEndpoints() { 
    for (String path : paths) { 
     //code for dynamic endpoint creation 
    } 
} 

private class MyHandle extends AbstractReplyProducingMessageHandler { 

    @Override 
    protected Object handleRequestMessage(Message<?> requestMessage) { 
     return this.getMessageBuilderFactory().withPayload("Your message: " + requestMessage.getPayload()); 
    } 
} 

당신이 말해 줄 수 내가 어떻게 할 수

?

답변

0

Java DSL 1.2부터 IntegrationFlow 및 종속 Bean을 동적으로 등록하는 경우에는 IntegrationFlowContext이 정확하게 사용 사례에 해당합니다.

https://spring.io/blog/2016/09/27/java-dsl-for-spring-integration-1-2-release-candidate-1-is-available

유전자 알고리즘 릴리스 오늘

.

블로그 게시물의 샘플을 따르고 org.springframework.integration.dsl.http.Http 공장에주의를 기울여야합니다.

하지만 가능한 한 빨리하십시오. @PostConstruct은이 사용 사례에 적합한 단계입니다. 나중에있을 때 HandlerMapping은 새 매핑을 검색하지 못합니다. 그냥 afterPropertiesSet()에서 스캔을하기 때문입니다.