Skip to content

Change DeadLetterPublishingRecoverer constructor signature to accept ? extends KafkaOperations #3913

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
sh-cho opened this issue May 19, 2025 · 0 comments

Comments

@sh-cho
Copy link
Contributor

sh-cho commented May 19, 2025

Expected Behavior

@Bean
public DeadLetterPublishingRecoverer publisher(KafkaTemplate<?, ?> stringTemplate,
        KafkaTemplate<?, ?> bytesTemplate) {
    Map<Class<?>, KafkaTemplate<?, ?>> templates = new LinkedHashMap<>();
    templates.put(String.class, stringTemplate);
    templates.put(byte[].class, bytesTemplate);
    return new DeadLetterPublishingRecoverer(templates);
}

This should be ok

Current Behavior

$ ./gradlew build
...

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler output below.
  /.../config/KafkaConfig.java:161: error: no suitable constructor found for DeadLetterPublishingRecoverer(Map<Class<?>,KafkaTemplate<?,?>>)
          return new DeadLetterPublishingRecoverer(templates);
                 ^
      constructor DeadLetterPublishingRecoverer.DeadLetterPublishingRecoverer(KafkaOperations<? extends Object,? extends Object>) is not applicable
        (argument mismatch; Map<Class<?>,KafkaTemplate<?,?>> cannot be converted to KafkaOperations<? extends Object,? extends Object>)
      constructor DeadLetterPublishingRecoverer.DeadLetterPublishingRecoverer(Map<Class<?>,KafkaOperations<? extends Object,? extends Object>>) is not applicable
        (argument mismatch; Map<Class<?>,KafkaTemplate<?,?>> cannot be converted to Map<Class<?>,KafkaOperations<? extends Object,? extends Object>>)
  Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
  1 error

* Try:
> Check your code and dependencies to fix the compilation error(s)
> Run with --scan to get full insights.

BUILD FAILED in 981ms
1 actionable task: 1 executed

Compile error occurs, because constructor accept KafkaOperations as parameter. So In the example code above, templates type should be Map<Class<?>, KafkaOperations<?, ?>> templates = new LinkedHashMap<>(); for now.

This should be ? extends KafkaOperations so that KafkaTemplate can be a parameter.

Context

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant