title: How to configure kafka transaction manager with spring transaction in spring boot app
body: <p>I am using Kafka in the spring boot application. I want to perform operations in one transaction like given below.</p>
  <pre><code>listen(){
   produce()
   saveInDb()
  } 
  </code></pre>
  <p>and</p>
  <pre><code>operation(){
   saveInDB()
   produce()
  }
  </code></pre>
  <p>I have enabled Kafka transactions using the below configurations</p>
  <pre><code>spring:
    kafka:
      bootstrap-servers: localhost:19092,localhost:29092,localhost:39092
      producer:
        transaction-id-prefix: tx-
      consumer:
        enable-auto-commit: false
        isolation-level: read_committed
  </code></pre>
  <p>and using this configuration</p>
  <pre><code>    @Bean
      public ProducerFactory&lt;String, Object&gt; producerFactory() {
          Map&lt;String, Object&gt; props = new HashMap&lt;&gt;();
          props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
          props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
          props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, JsonSerializer.class);
          DefaultKafkaProducerFactory&lt;String, Object&gt; factory = new DefaultKafkaProducerFactory&lt;&gt;(props);
          factory.setTransactionIdPrefix(&quot;tx-&quot;);
          return factory;
      }
  
      @Bean
      public KafkaTransactionManager kafkaTransactionManager() {
          KafkaTransactionManager manager = new KafkaTransactionManager(producerFactory());
          return manager;
      }
      @Bean
      public KafkaTemplate&lt;String, Object&gt; kafkaTemplate() {
          return new KafkaTemplate&lt;&gt;(producerFactory());
      }
  </code></pre>
  <p>But I am getting an error when tried with spring @Transactional annotation</p>
  <pre><code>@Transactional
  operation(){
   saveInDB()
   produce()
  } 
  </code></pre>
  <pre><code>No bean named 'transactionManager' available: No matching TransactionManager bean found for qualifier 'transactionManager' - neither qualifier match nor bean name match!
  </code></pre>
  <p>I followed the spring docs here
  <a href="https://docs.spring.io/spring-kafka/reference/html/#using-kafkatransactionmanager" rel="nofollow noreferrer">https://docs.spring.io/spring-kafka/reference/html/#using-kafkatransactionmanager</a></p>
  <p>What am I missing in the configuration?</p>