Я пытаюсь загрузить зашифрованные свойства, используя Jasypt's EncryptablePropertyPlaceholderConfigurer
.Spring исключает исключение, пытаясь разрешить заполнитель свойств с использованием зашифрованного заклада собственности Jasypt
Вот мой контекст приложения, с нарушившей фасолью и зашифрованным свойством заполнителя бобом:
<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 делает замену в редакторе!
примечание стороны, не думаю, что это релевантно, но этот весенний контекст загружается через контекст сервлета Джерси 2.
Вот исключение:
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)
Этот ответ поразительно эффективен в своей простоте. У меня есть только одно дополнение: в моем случае я должен был добавить атрибут order = "1" в place-placeholder для того, чтобы контекстные параметры в моем web.xml обрабатывались. –