我試着在谷歌上查找有關該問題,但無法獲得解決方案。Spring MethodInvokingBean - DriverManagerDataSource不接受返回的值
我想實現
請參見下面的代碼,我所要做的是通過一個加密的密碼MethodInvokingBean
,它採用com.xxxxxxx.CryptoUtil
使用靜態方法decrypt
解密。
解密後的值通過<property name="password" ref="decryptedDBPassword" />
注入masterDBDatasource
,但不起作用。
<bean id="decryptedDBPassword" class="org.springframework.beans.factory.config.MethodInvokingBean">
<property name="targetClass" value="com.xxxxxxx.CryptoUtil"/>
<property name="targetMethod" value="decrypt"/>
<property name="arguments" value="${encrypted.db.password}" />
</bean>
<bean id="masterDBDatasource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${db.driver.class}" />
<property name="url" value="${db.url}" />
<property name="username" value="${db.username}" />
<property name="password" ref="decryptedDBPassword" />
</bean>
異常
org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'org.springframework.beans.factory.config.MethodInvokingBean' to required type 'java.lang.String' for property 'password'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [org.springframework.beans.factory.config.MethodInvokingBean] to required type [java.lang.String] for property 'password': no matching editors or conversion strategy found
我也跟着下面的教程作爲參考
https://www.mkyong.com/spring/spring-methodinvokingfactorybean-example/
我也試過 但DB連接是說 - 訪問被拒絕因無效的密碼。
請幫忙。