在所有卡夫卡相关的配置类上加,此注解
@Conditional(MyCondition.class)
其中MyCondition,自己实现
package com.ireal.crpas.kafkademo.test;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.Producer;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.env.Environment;
import org.springframework.core.type.AnnotatedTypeMetadata;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Properties;
/**
* kafka 动态启动
* kafka代理服务器正常时启动kafka服务
* kafka代理服务器不可用时,不启动kafka服务