【发布时间】:2020-04-22 18:30:31
【问题描述】:
我得到 **原因:org.springframework.beans.TypeMismatchException:无法将“java.lang.String”类型的值转换为所需的“java.lang.Boolean”类型;嵌套异常是 java.lang.IllegalArgumentException: **
我相信这是由于缺少弹簧占位符配置而发生的。但是我在应用程序上下文中初始化了 bean 并且仍然收到此错误。谁能帮帮我??
@Value("${com.test.isTestEnable")
public Boolean isTestEnable;
弹簧属性类
public class SpringPropertiesUtil extends PropertyPlaceholderConfigurer {
private static HashMap<String, String> systemPropertiesMap;
private int springSystemPropertiesMode = SYSTEM_PROPERTIES_MODE_FALLBACK;
public static String getProperty(final String name) {
return systemPropertiesMap.get(name);
}
@Override
protected void processProperties(final ConfigurableListableBeanFactory beanFactory, final Properties props) throws BeansException {
super.processProperties(beanFactory, props);
systemPropertiesMap = new HashMap<String, String>();
for (final Object key : props.keySet()) {
final String keyStr = key.toString();
final String valueStr = resolvePlaceholder(keyStr, props, springSystemPropertiesMode);
systemPropertiesMap.put(keyStr, valueStr);
}
}
@Override
public void setSystemPropertiesMode(final int systemPropertiesMode) {
super.setSystemPropertiesMode(systemPropertiesMode);
springSystemPropertiesMode = systemPropertiesMode;
}
我的应用程序上下文文件
<bean id="placeholderConfig" class="com.test.SpringPropertiesUtil">
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
<property name="locations">
<list>
<value>file:${config.path}/application.properties</value>
<value>file:${config.path}/log.properties</value>
</list>
</property>
</bean>
【问题讨论】:
标签: spring-boot