在 application.properties 里面有一个以下的属性
spring.cloud.nacos.password=密文
dubbo.registry.parameters.password=密文
百度查询在 springboot 可以通过继承 EnvironmentPostProcessor 接口来重写配置文件的属性,代码:
@SneakyThrows
@Override
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
String dubboPassword = environment.getProperty("dubbo.registry.parameters.password");
String nacosPassword = environment.getProperty("spring.cloud.nacos.password");
dubboPassword = AESHelper.AESDecrypt(dubboPassword, BaseRSAUtils.getDefaultPublicKey());
nacosPassword = AESHelper.AESDecrypt(nacosPassword, BaseRSAUtils.getDefaultPublicKey());
Properties properties = new Properties();
properties.setProperty("dubbo.registry.parameters.password", dubboPassword);
properties.setProperty("spring.cloud.nacos.password", nacosPassword);
MutablePropertySources propertySources = environment.getPropertySources();
propertySources.addFirst(new PropertiesPropertySource("nacos-properties", properties));
}
启动的时候,发生 nacos 会直接报错密码错误,现在猜测是 nacos 建立链接是在解密代码之前。dubbo 可以正常解密。想问一下应该怎么做,才能在 nacos 建立连接之前把配置文件进行解密