[英]org.springframework.beans.NotWritablePropertyException. Invalid property <blah> is not writable or has an invalid setter method
I have the requirement to remove all passwords and encryption keys from the source code of my project.我需要从项目的源代码中删除所有密码和加密密钥。 I'm struggling to get this to work in my spring-servlet.xml file.
我正在努力让它在我的 spring-servlet.xml 文件中工作。 This worked before I tried making the change:
这在我尝试进行更改之前有效:
I want to move the jdbc_server_properties file to the filesystem and include the key in the file.我想将 jdbc_server_properties 文件移动到文件系统并在文件中包含密钥。
This is my last (of at least 25) attempt at getting this to work.这是我最后一次(至少 25 次)尝试让它发挥作用。
<bean id="propertyConfigurer" class="org.jasypt.spring4.properties.EncryptablePropertyPlaceholderConfigurer">
<constructor-arg ref="standardEncryptor" />
<property name="jdbcUsername" value="JDBC_USERNAME" />
<property name="jdbcPassword" value="JDBC_PASSWORD" />
<property name="jdbcUrl" value="JDBC_URL" />
<property name="jdbcDriver" value="JDBC_DRIVER" />
<property name="locations">
<list>
<value>file:///${USERPROFILE}/credentials/jdbc_server.properties</value>
</list>
</property>
</bean>
<bean id="standardEncryptor" 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="passwordSysPropertyName" value="ENCRYPTION_PASSWORD" />
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close" p:driverClassName="${jdbcDriver}" p:url="${jdbcUrl}"
p:username="${jdbcUsername}" p:password="${jdbcPassword}">
</bean>
Using the above configuration, I get a NotWritablePropertyException exception.使用上面的配置,我得到一个 NotWritablePropertyException 异常。 I've seen tons of posts on this issue but not where both the properties and encryption key are in a file on the filesystem.
我已经看到了大量关于这个问题的帖子,但没有看到属性和加密密钥都在文件系统上的文件中。 When this was working and the properties were read from a file in the classpath, there were no getters/setters for jdbcUsername (or the other properties) so I don't know why it's failing in this way now.
当它工作并且从类路径中的文件中读取属性时,jdbcUsername(或其他属性)没有getter / setter,所以我不知道为什么它现在以这种方式失败。
I tried adding the getters and setters (as String) to my BaseDaoImpl class but I still get the same error so if I'm supposed to add them, I'm not sure where they go.我尝试将 getter 和 setter(作为字符串)添加到我的 BaseDaoImpl class 但我仍然遇到相同的错误,所以如果我应该添加它们,我不确定它们在哪里 go。
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'propertyConfigurer' defined in ServletContext resource [/WEB-INF/spring-servlet.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'jdbcUsername' of bean class [org.jasypt.spring4.properties.EncryptablePropertyPlaceholderConfigurer]: Bean property 'jdbcUsername' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1568)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1276)
at ...
That is probably because jdbcUsername
is not a property of EncryptablePropertyPlaceholderConfigurer
.这可能是因为
jdbcUsername
不是EncryptablePropertyPlaceholderConfigurer
的属性。
Please, try something like this (just remove the jdbc*
properties from the EncryptablePropertyPlaceholderConfigurer
configuration, and use it directly in your dataSource
bean):请尝试这样的事情(只需从
EncryptablePropertyPlaceholderConfigurer
配置中删除jdbc*
属性,然后直接在您的dataSource
bean 中使用它):
<bean id="propertyConfigurer" class="org.jasypt.spring4.properties.EncryptablePropertyPlaceholderConfigurer">
<constructor-arg ref="standardEncryptor" />
<property name="locations">
<list>
<value>file:///${USERPROFILE}/credentials/jdbc_server.properties</value>
</list>
</property>
</bean>
<bean id="standardEncryptor" 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="passwordSysPropertyName" value="ENCRYPTION_PASSWORD" />
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close" p:driverClassName="${JDBC_DRIVER}" p:url="${JDBC_URL}"
p:username="${JDBC_USERNAME}" p:password="${JDBC_PASSWORD}">
</bean>
Assuming your jdbc_server.properties
file contains the required information:假设您的
jdbc_server.properties
文件包含所需的信息:
JDBC_USERNAME=ENC(...)
JDBC_PASSWORD=ENC(...)
JDBC_URL=ENC(...)
JDBC_DRIVER=your.jdbc.driver
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.