最近升级了spring cloud版本,遇到非常多的坑。其中在spring-config-server配置加解密时,用keystore方式生成
配置如下:
encrypt.key-store.location=classpath:miniserver.ks
encrypt.key-store.alias=minikey
encrypt.key-store.secret=123456
encrypt.key-store.password=123456
发现一直报错找不到 RsaProperties 类如下:
***************************
APPLICATION FAILED TO START
***************************
Description:
Field rsaProperties in org.springframework.cloud.config.server.config.EncryptionAutoConfiguration$KeyStoreConfiguration required a bean of type 'org.springframework.cloud.bootstrap.encrypt.RsaProperties' that could not be found.
Action:
Consider defining a bean of type 'org.springframework.cloud.bootstrap.encrypt.RsaProperties' in your configuration.
通过新旧版源码对比,发现RsaProperties是新增加的类,Dalston版不存在该类
打开RsaProperties发现
@ConditionalOnClass(RsaAlgorithm.class)
@ConfigurationProperties("encrypt.rsa")
public class RsaProperties {
其中@ConditionalOnClass注解限制了只有加载到RsaAlgorithm.class才会继续加载生成RsaProperties
从而找到RsaAlgorithm类,发现此类是并没有注解,是spring自动装配加载的,找到spring-autoconfigure-metadata.properties
配置文件中存在此类
配置文件需要放在 bootstrap
放入bootstrap 一切启动正常,可以正常使用