1

I use @ConfigurationProperties for configurating properties:

@Getter
@Setter
@ConfigurationProperties("kafka")
public class KafkaConnectionSettings {
 private String bootstrapAddress = "dataflow-kafka:9092";
{

And trying to autowire it in other configuration-class. For example:

@Configuration
@AllArgsConstructor
public class KafkaProducerConfig {
 private KafkaConnectionSettings kafkaSettings;
@Bean
public ProducerFactory<String, String> producerFactory() {
 Map<String, Object> configProps = new HashMap<>();
 configProps.put(
 ProducerConfig.BOOTSTRAP_SERVERS_CONFIG,kafkaSettings.getBootstrapAddress());
 }
}

But I receive the following exeption:

No qualifying bean of type 'com.app.config.kafka.KafkaConnectionSettings' available: expected single matching bean but found 2: kafkaConnectionSettings,kafka-com.app.config.kafka.KafkaConnectionSettings

Its a "little" strange, considering that in "com.app.config"-package I have a similar config:

 @Getter
 @Setter
 @ConfigurationProperties("app")
public class FileSettings {
}

and this last authowired successfully in classes, annotated with @Service

What am I doing wrong?

asked Feb 8, 2021 at 10:18
2
  • Hi, you have 2 spring beans with same return type. You can use a @Qualifier on expected one and on a later step, you can remove or merge unexpected one, removing qualifier annotation. Commented Feb 8, 2021 at 11:18
  • Gweltaz Niquel, thank you for your attempt. But my question was not quite clear. I answered on my question, by clarifying, that I use test context. Commented Feb 8, 2021 at 12:10

1 Answer 1

5

The problem is solved. I forgot to add KafkaConnectionSettings.class in @EnableConfigurationProperties at my testclass

@ActiveProfiles("test")
@EnableConfigurationProperties({FileSettings.class, KafkaConnectionSettings.class})
@RunWith(SpringRunner.class)
@SpringBootTest
public class AppTest {

Sorry for not quite clear question.

answered Feb 8, 2021 at 12:08
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.