Spring抛出异常,试图使用Jasypt加密属性占位符解析属性占位符

马拉松

我正在尝试使用Jasypt的加载加密的属性EncryptablePropertyPlaceholderConfigurer

这是我的应用程序上下文,其中包含令人讨厌的Bean和加密的属性占位符Bean:

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
  http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

    <context:property-placeholder/>

    <bean class="com.blahblah.OffendingBean">
        <property name="user" value="${my.user}"/>
        <property name="password" value="${my.password}"/>
    </bean>

    <bean id="propertyConfigurer"
          class="org.jasypt.spring3.properties.EncryptablePropertyPlaceholderConfigurer">
        <constructor-arg ref="configurationEncryptor"/>
        <property name="ignoreUnresolvablePlaceholders" value="true"/>
        <property name="locations">
            <list>
                <value>credentials.properties</value>
            </list>
        </property>
    </bean>

    <bean id="configurationEncryptor" class="org.jasypt.encryption.pbe.StandardPBEStringEncryptor">
        <property name="config" ref="environmentVariablesConfiguration"/>
    </bean>

    <bean id="environmentVariablesConfiguration"
          class="org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig">
        <property name="algorithm" value="PBEWithMD5AndDES"/>
        <property name="password" value="not telling you"/>

    </bean>
</beans>

注意我已经<property name="ignoreUnresolvablePlaceholders" value="true"/>设置了属性占位符。

我已经在调试器中逐步解决了这个问题,似乎另一个Property Placeholder实例来自某个地方,并决定未在任何地方设置$ {my.user}并引发异常。

奇怪的是,这工作得很好-我不知道我改变了什么来打破了这一点。

可以肯定地找到了prop文件“ credentials.properties”-EncryptablePropertyPlaceholderConfigurer并未对此抱怨。它绝对具有其中定义的属性my.user。甚至Intellij也在编辑器中进行替换!

旁注,不认为这是相关的,但是此春季上下文是通过Jersey 2 servlet上下文加载的。

这是例外:

org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'com.blahblah.OffendingBean#0' defined in class path resource [applicationContext.xml]: Could not resolve placeholder 'my.user' in string value "${my.user}"
    at org.springframework.beans.factory.config.PlaceholderConfigurerSupport.doProcessProperties(PlaceholderConfigurerSupport.java:209)
    at org.springframework.context.support.PropertySourcesPlaceholderConfigurer.processProperties(PropertySourcesPlaceholderConfigurer.java:174)
    at org.springframework.context.support.PropertySourcesPlaceholderConfigurer.postProcessBeanFactory(PropertySourcesPlaceholderConfigurer.java:151)
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694)
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:669)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:461)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:93)
    at org.glassfish.jersey.server.spring.SpringComponentProvider.createXmlSpringConfiguration(SpringComponentProvider.java:164)
    at org.glassfish.jersey.server.spring.SpringComponentProvider.createSpringContext(SpringComponentProvider.java:155)
    at org.glassfish.jersey.server.spring.SpringComponentProvider.initialize(SpringComponentProvider.java:98)
马拉松

小童,这解决了它:

已更改:

<context:property-placeholder/>

<context:property-placeholder ignore-unresolvable="true"/>

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

jasypt属性占位符不起作用

来自分类Dev

使用属性占位符位置

来自分类Dev

使用属性占位符位置

来自分类Dev

Spring配置文件和属性占位符异常

来自分类Dev

获取Spring属性占位符及其解析值的列表

来自分类Dev

Spring占位符无法解析JavaConfig中的属性

来自分类Dev

获取Spring属性占位符及其解析值的列表

来自分类Dev

Spring Boot:更改属性占位符

来自分类Dev

spring-boot属性占位符

来自分类Dev

spring-boot属性占位符

来自分类Dev

无法在logback.xml中使用Spring属性占位符

来自分类Dev

如何告诉Spring使用Java映射来解析属性占位符?

来自分类Dev

在自己的属性占位符配置器中使用其他属性占位符的属性

来自分类Dev

速度-遍历占位符的属性

来自分类Dev

Spring无法解析占位符

来自分类Dev

为什么Jasypt不管ENC(前缀)为何都尝试解密Camel属性占位符?

来自分类Dev

Mule-Groovy组件内部的Spring属性占位符

来自分类Dev

无法解析占位符| 春季占位符

来自分类Dev

如何通过Swift在iOS中使用属性占位符

来自分类Dev

在Xpages中使用占位符属性和密码类型

来自分类Dev

在Opera mini中检测到占位符属性,但未使用

来自分类Dev

使用javascript设置表单字段占位符属性

来自分类Dev

Jsoup正在使用占位符值删除href属性

来自分类Dev

Eclipse HTML:占位符不是属性吗?

来自分类Dev

HTML中的值与占位符属性

来自分类Dev

占位符中的ng-maxlength属性

来自分类Dev

jquery更改占位符属性值

来自分类Dev

XHTML 不支持属性占位符

来自分类Dev

如何在Spring xml中使用属性占位符使骆驼简单表达式起作用