Java 修剪jasypt EncryptablePropertyPlaceHolderConfigure中的尾随空格

Java 修剪jasypt EncryptablePropertyPlaceHolderConfigure中的尾随空格,java,eclipse,spring,jasypt,Java,Eclipse,Spring,Jasypt,我们正在使用Spring和jasyptEncryptablePropertyPlaceHolderConfigure来读取application.properties文件 如果某些属性值的结尾包含空格,则有时会出现问题。在使用@value(${})标记读取值时,我们也会在结尾处获得尾随空格,这会造成问题 现在,EncryptablePropertyPlaceHolderConfigure类是final,因此无法扩展,我搜索了很多,以确定在修剪字符串值周围的空格后是否有任何方法可以获得属性 有人能

我们正在使用Spring和jasypt
EncryptablePropertyPlaceHolderConfigure
来读取application.properties文件

如果某些属性值的结尾包含空格,则有时会出现问题。在使用
@value(${})
标记读取值时,我们也会在结尾处获得尾随空格,这会造成问题

现在,EncryptablePropertyPlaceHolderConfigure类是final,因此无法扩展,我搜索了很多,以确定在修剪字符串值周围的空格后是否有任何方法可以获得属性


有人能建议如何处理这种情况吗?

您可以使用传入构造函数的自定义StringEncryptor创建EncryptablePropertyPlaceHolderConfigure。在此CustomStringEncryptor.decrypt()中,执行修剪()。(在这种情况下,您不知道要解密的属性是什么)

您可以通过委派绕过final:

class CustomStringEncryptor implements StringEncryptor{
  private StringEncryptor delegate;

  public CustomStringEncryptor(StandardPBEStringEncryptor delegate){
    this.delegate = delegate;
  }

  String decrypt(String encryptedMessage){
    String message = this.delegate.decrypt(encryptedMessage);
    if(null != message) message = message.trim();
    return message;
  }
}

所以我在“bellabax”的帮助下找到了问题的答案 我重写了属性持久化器并实现了自己的方法

propertyConfigurator.setPropertiesPersister(new MyDefaultPropertiesPersister());

@覆盖
公共void加载(Properties props,InputStream is)引发IOException{
道具载荷(is);
for(条目属性:props.entrySet()){
property.setValue(property.getValue().toString().trim());
}
}
现在,我的属性被修剪为尾随空间
我希望这对某些人有所帮助。

您好,感谢您的建议,我们已经使用StandardPBEStringEncryptor作为字符串加密器,这个类也是最后一个类。我试着在这个类的decrypt方法中放置一个调试点,但它永远不会在那里结束。大多数属性都是简单的文本,没有被ENC()包围,这很好!这是我的第一个选择,但我放弃了它们,因为我认为PropertiesPersister以ENC(xxx)形式加载属性,而不是作为解密值(并且不能将()值修剪为ENC(…),这没有意义)。我的建议只是从阅读javadoc中推断出来的,我没有尝试,因为我从未使用过mjasthanks。我的要求只是修剪=右侧的任何值,不管它是否被ENC包围。
    @Override
    public void load(Properties props, InputStream is) throws IOException {

    props.load(is);
    for (Entry<Object, Object> property : props.entrySet()) {
        property.setValue(property.getValue().toString().trim());
    }
}