A tip in Spring IOC
These days, I’m learning how Apache Kafka is used in Springboot. And I found an interesting tip in Springboot ioc.
Before, I injected the bean into another bean like this:
1 |
|
Or like this:
1 |
|
But, when I learned with this tutorial, the author inject the kafkaTemplate
like this:
1 |
|
In other words, this way of injecting without @Autowired
, made me feel amazed.
He said Spring framework will automatically inject this dependency(kafkaTemplate
) whenever this bean(KafkaProducer
) has only one parameterized constructor. I think is a useful and elegant way.