我使用 Spring-jdbc 和 org.apache.commons.dbcp.BasicDataSource 使用连接的用户名和密码。我想使用 BasicDataSource,因为我只有一个连接。
我有这段代码:
<bean class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"
id="dataSource">
<property name="driverClassName" value="${database.driverClassName}" />
<property name="url" value="${database.url}" />
<property name="username" value="${database.username}" />
<property name="password" value="${database.password}" />
</bean>
现在我必须使用基于 Oracle Wallet 的身份验证,在没有 Spring 的情况下,我在简单的应用程序测试中没有问题,但我无法将这个新的身份验证与 Spring 集成。有谁知道我该怎么做??
最佳答案
您提到“简单应用程序测试”,所以我假设您需要配置单元测试。在单元测试配置类(例如 class TestSpringWebConfig extends SpringWebConfig
)中,这会为您提供一个使用钱包的 Oracle 数据源(奖励:以下使用代理数据库帐户):
System.setProperty("oracle.net.tns_admin", "path/to/your/tnsnames");
OracleDataSource ds = new OracleDataSource();
Properties props = new Properties();
props.put("oracle.net.wallet_location", "(source=(method=file)(method_data=(directory=path/to/your/wallet)))");
/*
Use the following only if you have a proxy user database account instead of a normal DB account
A test user's username could go here though
*/
props.put(OracleConnection.CONNECTION_PROPERTY_PROXY_CLIENT_NAME, "proxy-user-name");
ds.setConnectionProperties( props );
ds.setURL("jdbc:oracle:thin:/@dbAlias"); //dbAlias should match what's in your tnsnames
return ds;
这还假设您的 JDK 中有以下内容:
在 JAVA_HOME/jre/lib/security/java.security 中,将以下内容添加到“提供程序列表”中:
security.provider.11=oracle.security.pki.OraclePKIProvider
然后从 Oracle 添加以下 jar 到 JAVA_HOME/jre/lib/ext:
- osdt_cert.jar
- osdt_core.jar
- oraclepki.jar
当然,以上所有内容都假定 ojdbc7 jar 已经在您的应用程序的类路径中。
关于java - 使用 Oracle Wallet 身份验证从 Spring-jdbc 连接到 Oracle DB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24909125/