我正在使用 PropertiesFactoryBean 从典型的属性文件加载属性。有没有办法让 Spring 自动修剪 prop 值中的尾随空白?
最佳答案
由于这在使用 Spring Boot 时通常会造成混淆,我想补充一点,您不需要 XML 配置来提供您自己的 PropertyPlaceholderConfigurer
.
简单地把它放在你的主类中:
@Bean
public static PropertySourcesPlaceholderConfigurer createPropertyConfigurer()
{
PropertySourcesPlaceholderConfigurer propertyConfigurer = new PropertySourcesPlaceholderConfigurer();
propertyConfigurer.setTrimValues(true);
return propertyConfigurer;
}
这足以修剪来自 application.properties
的值。 .
关于java - 为加载到 Spring 的 Props 文件中的属性自动修剪尾随空白,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7031905/