title: Is it possible to disable spring-cloud-stream's functional binding for a specific method?
body: <p>I have a Spring Boot based library (using spring-data-mongo) that creates a <code>PersistentEntities</code> bean. <code>PersistentEntities</code> happens to implement the <code>Supplier&lt;T&gt;</code> interface, so the Spring Cloud Stream functional binder is creating a binding to it. More specifically, <code>BeanFactoryAwareFunctionRegistry.discoverDefaultDefinitionIfNecessary</code> finds it as a bean of type <code>Supplier</code>.</p>
  
  <p>We are using the Spring Cloud Streams Kafka binder, so Spring tries to publish each of these objects to a Kafka topic it creates. This causes an infinite recursion issue in the JSON serializer:</p>
  
  <blockquote>
    <p>2019-12-04 15:36:54.323 ERROR 1 --- [   scheduling-1] o.s.i.h.LoggingHandler                   : org.springframework.messaging.MessagingException: Failed to invoke method; nested exception is org.springframework.messaging.converter.MessageConversionException: Could not write JSON: Infinite recursion (StackOverflowError) (through reference chain: org.springframework.data.mongodb.core.mapping.BasicMongoPersistentEntity["idProperty"] -> org.springframework.data.mongodb.core.mapping.CachingMongoPersistentProperty["owner"] -> org.springframework.data.mongodb.core.mapping.BasicMongoPersistentEntity["idProperty"] -> org.springframework.data.mongodb.core.mapping.CachingMongoPersistentProperty["owner"] -> org.springframework.data.mongodb.core.mapping.BasicMongoPersistentEntity["idProperty"] -> org.springframework.data.mongodb.core.mapping.CachingMongoPersistentProperty["owner"] -> org.springframework.data.mongodb.core.mapping.BasicMongoPersistentEntity["idProperty"] -> org.springframework.data.mongodb.core.mapping.CachingMongoPersistentProperty["owner"] -> org.springframework.data.mongodb.core.mapping.BasicMongoPersistentEntity["idProperty"] -> org.springframework.data.mongodb.core.mapping.CachingMongoPersistentProperty["owner"] -> org.springframework.data.mongodb.core.mapping.BasicMongoPersistentEntity["idProperty"] -> org.springframework.data.mongodb.core.mapping.CachingMongoPersistentProperty["owner"]
    ...</p>
  </blockquote>
  
  <p>Is there a way to exclude my bean from function binding? The project consuming this library isn't using Spring Cloud Function, but I'd prefer to leave that possibility open.</p>
  
  <p>For reference, my bean is defined as:</p>
  
  <pre><code>@Bean
  public PersistentEntities myPersistentEntities(List&lt;MongoTemplate&gt; mongoTemplates) {
      return new PersistentEntities(() -&gt; {
          List&lt;MappingContext&lt;?, ?&gt;&gt; mappingContexts = mongoTemplates.stream().map(t -&gt; t.getConverter().getMappingContext()).collect(Collectors.toList());
          return mappingContexts.iterator();
      });
  }
  </code></pre>
  
  <p>We just upgraded Spring Cloud from Greenwich to Hoxton, so the automatic functional bindings are new to us.</p>