使用Oracle Wallet身份validation从Spring-jdbc连接到Oracle DB

我使用Spring-jdbc和org.apache.commons.dbcp.BasicDataSource使用用户名和密码进行连接。 我想使用BasicDataSource,因为我只有一个连接。

我有这个代码:

      

现在我必须使用基于Oracle Wallet的身份validation,在没有Spring的简单应用程序测试中我没有问题,但我无法将此新身份validation与Spring集成。 有谁知道我怎么做?

你提到“简单的应用程序测试”,所以我假设你需要配置你的unit testing。 在unit testing配置类中(例如, 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 

并将以下jar从Oracle添加到JAVA_HOME / jre / lib / ext:

  • osdt_cert.jar
  • osdt_core.jar
  • oraclepki.jar

当然,以上所有假设ojdbc7 jar已经在你的应用程序的类路径中了。