Home > Back-end >  what does "spring-kafka without springboot" mean
what does "spring-kafka without springboot" mean

Time:10-05

I'm totally new to Kafka and terribly confused by this:

https://docs.spring.io/spring-kafka/reference/html/#with-java-configuration-no-spring-boot

I don't understand what that even means. What does "no spring boot mean" because that example sure as hell uses spring boot. I'm so confused....

EDIT

if I'm using SpringBoot and spring-kafka, should I have to manually create @Bean ConcurrentKafkaListenerContainerFactory as shown here. Most of the examples in the docs for setting up filtering / config / etc seem to use the "manual" configuration using @Bean. Is that "normal"? The docs are very confusing to me...especially this warning:

Spring for Apache Kafka is designed to be used in a Spring Application Context. For example, if you create the listener container yourself outside of a Spring context, not all functions will work unless you satisfy all of the …​Aware interfaces that the container implements.

CodePudding user response:

It's referring to the autowired configuration, as compared to putting each property in the config via HashMap/Properties in-code.

Also, it does not use @SpringBootApplication or SpringApplication.run, it just calls a regular main method using a hard-coded Config class.

CodePudding user response:

Spring boot contains the functionality of AutoConfiguration

What this means is that spring boot when discovers some specific jar dependencies it knows, in the project, it automatically configures them to work on a basic level. This does not exist in simple Spring project where even if you add the dependency you have to also provide the configuration as to how it should work in your application.

This is also happening here with dependencies of Kafka. Therefore the documentation explains what more you have to configure if you don't have spring-boot with auto-configuration to make kafka work in a spring project.

Another question asked in comment is what happens in case you want some complex custom configuration instead of the automatic configuration provided while you are in a spring-boot app.

As documented

Auto-configuration tries to be as intelligent as possible and will back-away as you define more of your own configuration. You can always manually exclude() any configuration that you never want to apply (use excludeName() if you don't have access to them). You can also exclude them via the spring.autoconfigure.exclude property.

So if you want to have some complex configuration which is not automatically provided by spring-boot through some other mechanism like a spring-boot specific application property, then you can make your own configuration with your custom bean and then either automatic configuration from spring-boot for that class will back of as spring does several intelligent checks during application context set up or you will have to exclude the class from auto configuration manually.

In that case you could probably take as an example reference of how to register manually your complex configurations in spring boot what is documented on how to be done in non spring boot app. doc

  • Related