我在我的spring应用程序上下文中这样配置db:
<bean id="dataSource"
class="org.springframework.jdbc.datasource.SingleConnectionDataSource">
<property name="driverClassName"
value="oracle.jdbc.driver.OracleDriver" />
<property name="url" value="${uri}"/>
<property name="username" value="${user}"/>
<property name="password" value="${password}"/>
</bean>
但是,我决定对密码进行编码。为了在xml文件中正确地读取它,我编写了一个自定义的:
public class CustomDataSource extends BasicDataSource {
private String username;
private String password;
public DataSource createDataSource() {
// get the value and decrypt here and set
BasicDataSource target = new BasicDataSource();
target.setPassword()
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
System.out.println("setng user ");
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
更新的bean是:
<bean id = "customDatasource" class = "CustomDataSource" />
<bean id = "datasource"
factory-bean = "customDatasource" factory-method = "createDataSource">
<property ... />
</bean>
但是我无法将xml文件中的值传递给自定义bean,知道我做错了什么吗?注意basicdatasource的类型为:org.apache.commons.dbcp2
暂无答案!
目前还没有任何答案,快来回答吧!