4
votes

when I using the configuration as described in spring docs:

@Configuration
@EnableIntegration
public class MyFlowConfiguration {

    @Bean
    @InboundChannelAdapter(value = "inputChannel", poller = @Poller(fixedDelay = "1000"))
    public MessageSource<String> consoleSource() {
        return CharacterStreamReadingMessageSource.stdin();
    }

    @Bean
    @Transformer(inputChannel = "inputChannel", outputChannel = "httpChannel")
    public ObjectToMapTransformer toMapTransformer() {
        return new ObjectToMapTransformer();
    }

    @Bean
    @ServiceActivator(inputChannel = "httpChannel")
    public MessageHandler httpHandler() {
        HttpRequestExecutingMessageHandler handler = new HttpRequestExecutingMessageHandler("http://foo/service");
        handler.setExpectedResponseType(String.class);
        handler.setOutputChannelName("outputChannel");
        return handler;
    }

    @Bean
    @ServiceActivator(inputChannel = "outputChannel")
    public LoggingHandler loggingHandler() {
        return new LoggingHandler("info");
    }

}

What kind of bean definition name I may use to reach the endpoints? When using configuration via components there is provided information in docs:

The processing of these annotations creates the same beans (AbstractEndpoints and MessageHandlers (or MessageSources for the inbound channel adapter - see below) as with similar xml components. The bean names are generated with this pattern: [componentName].[methodName].[decapitalizedAnnotationClassShortName] for the AbstractEndpoint and the same name with an additional .handler (.source) suffix for the MessageHandler (MessageSource) bean. The MessageHandlers (MessageSources) are also eligible to be tracked by Section 8.2, “Message History”.

But how it can be used here?

1

1 Answers

4
votes

If I understood correctly you want to inject some of those endpoints to your services. Not sure "why?", but it can be done like this (e.g. for that httpHandler):

@Autowire
@Qualifier("myFlowConfiguration.httpHandler.serviceActivator")
private AbstractEndpoint httpEndpoint;

According to the rule described above:

  • myFlowConfiguration - the bean name of the class which contains the method with @ServiceActivator. In your case it is your @Configuration

  • httpHandler the method name with @ServiceActivator

  • serviceActivator - the decapitalized name of the @ServiceActivator.

Is that clear ?

UPDATE

I don't use xml context, only java based configuration, so answer is @Import

Good, thanks. That is an answer. Any @Import @Configuration are present with bean names with fully-qualified class name including package (from ConfigurationClassPostProcessor):

/* using fully qualified class names as default bean names */
 private BeanNameGenerator importBeanNameGenerator = new   AnnotationBeanNameGenerator() {
    @Override
    protected String buildDefaultBeanName(BeanDefinition definition) {
        return definition.getBeanClassName();
    }
};

So, we have to keep that in mind, if we are going to use reference to endpoint from those unnamed class.

Of course, to simplify your life you can just add a name to your MyFlowConfiguration:

@Configuration("myFlowConfiguration")
@EnableIntegration
public class MyFlowConfiguration {