Connect to Oracle DB from Spring-jdbc with Oracle Wallet authentification
You mention "simple application test" so I'm assuming you need to configure your unit tests. In a unit test config class (for example class TestSpringWebConfig extends SpringWebConfig
) this gets you an Oracle datasource using a wallet (bonus: the following uses a proxy database account):
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 tnsnamesreturn ds;
This also assumes you have the following in your JDK:
In JAVA_HOME/jre/lib/security/java.security, add the following to the "List of providers":
security.provider.11=oracle.security.pki.OraclePKIProvider
And add the following jars from Oracle to JAVA_HOME/jre/lib/ext:
- osdt_cert.jar
- osdt_core.jar
- oraclepki.jar
And of course, all of the above assumes the ojdbc7 jar is in your application's classpath already.