【发布时间】:2021-03-29 04:44:09
【问题描述】:
我有以下代码:
@Value("#{${optional.currencies}}")
private Map<Account, Set<String>> mapAccountAndCurrencies= null;
但我得到以下异常:
Caused by: org.springframework.beans.ConversionNotSupportedException: Failed to convert value of type 'java.util.Collections$UnmodifiableRandomAccessList' to required type 'java.util.Map'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'java.util.Collections$UnmodifiableRandomAccessList' to required type 'java.util.Map': no matching editors or conversion strategy found
at org.springframework.beans.TypeConverterSupport.convertIfNecessary(TypeConverterSupport.java:76)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1235)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1207)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:636)
... 68 more
Caused by: java.lang.IllegalStateException: Cannot convert value of type 'java.util.Collections$UnmodifiableRandomAccessList' to required type 'java.util.Map': no matching editors or conversion strategy found
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:262)
at org.springframework.beans.TypeConverterSupport.convertIfNecessary(TypeConverterSupport.java:73)
... 71 more
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBatchTest
@EnableAutoConfiguration
@ContextConfiguration(classes= {BatchTestConfiguration.class})
@TestPropertySource(locations="classpath:application-test.properties")
public class BatchTest {
}
还有我的 applicatin-test.properties:
optional.currencies={}
我做错了什么?
【问题讨论】:
-
您好,请问您如何设置属性
optional.currencies?谢谢! -
感谢@KajHejer。我已经编辑了我的帖子
-
这对我有用,没有任何问题@sewey
-
@NicoVanBelle 仍然有同样的问题。我的实际批处理运行良好(使用类似的 application.properties)。只有在运行 BatchTest 时才会出现此错误。
标签: java spring-boot properties