我使用@configurationproperties配置属性:
@Getter
@Setter
@ConfigurationProperties("kafka")
public class KafkaConnectionSettings {
private String bootstrapAddress = "dataflow-kafka:9092";
{
并尝试在其他配置类中自动连接它。例如:
@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());
}
}
但我得到以下例外:
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
考虑到在“com.app.config”包中我有一个类似的配置,这有点奇怪:
@Getter
@Setter
@ConfigurationProperties("app")
public class FileSettings {
}
最后一个authowired在类中成功地用@service注解
我做错什么了?
1条答案
按热度按时间z0qdvdin1#
问题解决了。我忘了在testclass的@enableconfigurationproperties中添加kafkanConnectionSettings.class
对不起,这个问题不太清楚。