title: Creating generic KafkaTemplate in spring boot Kafka
body: <p>I am using spring Kafka to implement Kafka, which is cool. Now I want to create a generic Kafka template to send the message.</p>
  <p>Something like this</p>
  <pre><code>    public class ProductProducer&lt;T&gt; implements IProductProducer{
          private final KafkaTemplate&lt;String, T&gt; _template;
      
          public ProductProducer(KafkaTemplate&lt;String, T&gt; _template) {
              this._template = _template;
          }
      
          @Override
          public ProductViewModel GetProduct(String id) {
              this._template.send(ProductTopicConstants.GET_PRODUCT, id);
              return new ProductViewModel(&quot;&quot;,&quot;&quot;,0,&quot;&quot;);
          } 
  
         @Override
          public void AddProduct(ProductViewModel product) {
             this._template.send(ProductTopicConstants.ADD_PRODUCT, product);
          }
  
      }
  </code></pre>
  <p>For Kafka Key is always String, but the data might be a different models.</p>
  <p>I get the error as</p>
  <p><a href="https://i.stack.imgur.com/oa2u6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oa2u6.png" alt="enter image description here" /></a></p>
  <p><a href="https://i.stack.imgur.com/BLbFB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BLbFB.png" alt="enter image description here" /></a></p>