javaspring-bootspring-cloudspring-cloud-streamspring-cloud-function

Cloud Kafka with spring boot gives me errors


Hey I followed a step by step guide for setting up kafka in spring boot.

But now I cannot start the app. Any suggestions :)

error from the log:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'functionInitializer' defined in class path resource [org/springframework/cloud/stream/function/FunctionConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Found more then one function in BeanFactory: [persistentEntities, resourceMappings]. Consider providing 'spring.cloud.function.definition' property.

What is spring.cloud.function.definition? And how to set it up? Caused by: java.lang.IllegalArgumentException: Found more then one function in BeanFactory: [persistentEntities, resourceMappings]. Consider providing 'spring.cloud.function.definition' property.


Solution

  • Spring Cloud Function does the following within an application:

    1. Searches for ANY Spring managed bean that implements OR conforms with the contract of the functional interfaces Supplier<T>, Consumer<T> and Function<T, R>.
    2. Mark these beans as potential beans to be bound to event endpoints (bindings).
    3. If there is only one Spring managed bean resolved in step 1, then that bean will be the only bean bound as the function exposed (bound to external event endpoint) by the application - effectively assuming that the application is a Serverless Function.
    4. If there are more than a single Spring managed bean resolved in step 1, then Spring Cloud Function will look at the property spring.cloud.function.definition to resolved which of those beans should be bound to endpoints.
    5. If this property is not assigned, then Spring Cloud Function will throw a IllegalArgumentException (the one you are getting) complaining that it cannot resolve which beans (of all the potential functional bean that it has found) you want exposed.
    6. The value assigned to the property spring.cloud.function.definition will be read as a semi-colon separated list of functional bean names

    So, to solve your problem, you need to either:

    spring.cloud.function.definition=persistentEntities;resourceMappings
    

    Hope this helps.