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?
-
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.Gweltaz Niquel– Gweltaz Niquel2021年02月08日 11:18:30 +00:00Commented 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.Jelly– Jelly2021年02月08日 12:10:57 +00:00Commented Feb 8, 2021 at 12:10
1 Answer 1
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.
Comments
Explore related questions
See similar questions with these tags.