错误代码:
java.lang.ClassCastException: class java.util.Collections$UnmodifiableMap cannot be cast to class java.util.LinkedHashMap (java.util.Collections$UnmodifiableMap and java.util.LinkedHashMap are in module java.base of loader 'bootstrap')
at com.zhubayi.springbootbeanfactorypostprocessor.config.DecryptConfig.convertPropertySource(DecryptConfig.java:62) ~[classes/:na]
at com.zhubayi.springbootbeanfactorypostprocessor.config.DecryptConfig.lambda$postProcessBeanFactory$1(DecryptConfig.java:50) ~[classes/:na]
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511) ~[na:na]
at com.zhubayi.springbootbeanfactorypostprocessor.config.DecryptConfig.postProcessBeanFactory(DecryptConfig.java:50) ~[classes/:na]
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:358) ~[spring-context-6.0.6.jar:6.0.6]
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:201) ~[spring-context-6.0.6.jar:6.0.6]
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:747) ~[spring-context-6.0.6.jar:6.0.6]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:565) ~[spring-context-6.0.6.jar:6.0.6]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146) ~[spring-boot-3.0.4.jar:3.0.4]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:732) ~[spring-boot-3.0.4.jar:3.0.4]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:434) ~[spring-boot-3.0.4.jar:3.0.4]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:310) ~[spring-boot-3.0.4.jar:3.0.4]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1304) ~[spring-boot-3.0.4.jar:3.0.4]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1293) ~[spring-boot-3.0.4.jar:3.0.4]
at com.zhubayi.springbootbeanfactorypostprocessor.SpringBootBeanFactoryPostProcessorApplication.main(SpringBootBeanFactoryPostProcessorApplication.java:11) ~[classes/:na]
应为propertySource.getSource()
不能转为LinkedHashMap
解决办法
Map source=new LinkedHashMap<>();
source.putAll((Map) ps.getSource());