1.控制一:可以依据环境判断是否需要注册;
2.控制二:可以依据命令行参数判断是否需要注册;
代码示例:
package com.xxx.pay.common;
import com.alibaba.cloud.nacos.NacosDiscoveryProperties;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.boot.ApplicationArguments;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
@Component
@Slf4j
public class NacosDiscoveryPropertiesPostProcessor implements BeanPostProcessor {
private final ApplicationArguments args;
@Autowired
private Environment environment;
public NacosDiscoveryPropertiesPostProcessor(ApplicationArguments args) {
this.args = args;
}
@Override
public Object postProcessBeforeInitialization(Object be