title: Spring Boot Unable to determine jdbc url from datasource
body: <p>I'm building an application using spring boot and need to connect to Oracle DB via service, not sid. </p>
  
  <p>These are datasource settings:</p>
  
  <pre><code>spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
  spring.datasource.url=jdbc:oracle:thin:@//hostname.companyname.corp:1500/servicename.companyname.com
  spring.datasource.username=username
  spring.datasource.password=password
  spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.OracleDialect
  spring.jpa.properties.hibernate.default_schema=SCHEMA_NAME
  </code></pre>
  
  <p>I've already explored two other responses regarding tns connection:
  <a href="https://stackoverflow.com/questions/41424589/connection-to-oracle-via-tns-is-not-working">Connection to Oracle via TNS is not working</a>
  and 
  <a href="https://stackoverflow.com/questions/19536162/how-to-connect-jdbc-to-tns-oracle">How to connect JDBC to tns oracle</a></p>
  
  <p>But I'm hitting a different error:</p>
  
  <blockquote>
    <p>org.springframework.jdbc.support.MetaDataAccessException: Could not
    get Connection for extracting meta data; nested exception is
    org.springframework.jdbc.CannotGetJdbcConnectionException: Could not
    get JDBC Connection; nested exception is java.sql.SQLException    at
    org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:339)
    ~[spring-jdbc-4.3.13.RELEASE.jar:4.3.13.RELEASE]  at
    org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:366)
    ~[spring-jdbc-4.3.13.RELEASE.jar:4.3.13.RELEASE]  at
    org.springframework.boot.autoconfigure.orm.jpa.DatabaseLookup.getDatabase(DatabaseLookup.java:72)
    ~[spring-boot-autoconfigure-1.5.9.RELEASE.jar:1.5.9.RELEASE]  at
    org.springframework.boot.autoconfigure.orm.jpa.JpaProperties.determineDatabase(JpaProperties.java:139)
    [spring-boot-autoconfigure-1.5.9.RELEASE.jar:1.5.9.RELEASE]   at
    org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.jpaVendorAdapter(JpaBaseConfiguration.java:105)
    [spring-boot-autoconfigure-1.5.9.RELEASE.jar:1.5.9.RELEASE]   at
    org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration$$EnhancerBySpringCGLIB$$47d988e9.CGLIB$jpaVendorAdapter$4()
    [spring-boot-autoconfigure-1.5.9.RELEASE.jar:1.5.9.RELEASE]   at
    org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration$$EnhancerBySpringCGLIB$$47d988e9$$FastClassBySpringCGLIB$$27b4f4ca.invoke()
    [spring-boot-autoconfigure-1.5.9.RELEASE.jar:1.5.9.RELEASE]   at
    org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
    [spring-core-4.3.13.RELEASE.jar:4.3.13.RELEASE]   at
    org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:358)
    [spring-context-4.3.13.RELEASE.jar:4.3.13.RELEASE]    at
    org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration$$EnhancerBySpringCGLIB$$47d988e9.jpaVendorAdapter()
    [spring-boot-autoconfigure-1.5.9.RELEASE.jar:1.5.9.RELEASE]   at
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    ~[na:1.8.0_152]   at
    sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    ~[na:1.8.0_152]   at
    sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    ~[na:1.8.0_152]   at java.lang.reflect.Method.invoke(Unknown Source)
    ~[na:1.8.0_152]   at
    org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
    [spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]  at
    org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
    [spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]  at
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1173)
    [spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]  at
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1067)
    [spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]  at
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)
    [spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]  at
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
    [spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]  at
    org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
    [spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]  at
    org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    [spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]  at
    org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
    [spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]  at
    org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
    [spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]  at
    org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:208)
    [spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]  at
    org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1138)
    [spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]  at
    org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066)
    [spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]  at
    org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:835)
    [spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]  at
    org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:741)
    [spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]  at
    org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:467)
    [spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]  at
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1173)
    [spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]  at
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1067)
    [spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]  at
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)
    [spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]  at
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
    [spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]  at
    org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
    [spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]  at
    org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    [spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]  at
    org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
    [spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]  at
    org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
    [spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]  at
    org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:208)
    [spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]  at
    org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1138)
    [spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]  at
    org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066)
    [spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]  at
    org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:835)
    [spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]  at
    org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:741)
    [spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]  at
    org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:467)
    [spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]  at
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1173)
    [spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]  at
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1067)
    [spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]  at
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)
    [spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]  at
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
    [spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]  at
    org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
    [spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]  at
    org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    [spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]  at
    org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
    [spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]  at
    org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
    [spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]  at
    org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1080)
    [spring-context-4.3.13.RELEASE.jar:4.3.13.RELEASE]    at
    org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:857)
    [spring-context-4.3.13.RELEASE.jar:4.3.13.RELEASE]    at
    org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543)
    [spring-context-4.3.13.RELEASE.jar:4.3.13.RELEASE]    at
    org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
    [spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]     at
    org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693)
    [spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]     at
    org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360)
    [spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]     at
    org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
    [spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]     at
    org.springframework.boot.SpringApplication.run(SpringApplication.java:1118)
    [spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]     at
    org.springframework.boot.SpringApplication.run(SpringApplication.java:1107)
    [spring-boot-1.5.9.RELEASE.jar:1.5.9.RELEASE]     at
    com.swift.cpms.CpmsWebApp.main(CpmsWebApp.java:18) [classes/:na]
    Caused by: org.springframework.jdbc.CannotGetJdbcConnectionException:
    Could not get JDBC Connection; nested exception is
    java.sql.SQLException     at
    org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:80)
    ~[spring-jdbc-4.3.13.RELEASE.jar:4.3.13.RELEASE]  at
    org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:326)
    ~[spring-jdbc-4.3.13.RELEASE.jar:4.3.13.RELEASE]  ... 61 common frames
    omitted Caused by: java.sql.SQLException: null    at
    org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:323)
    ~[tomcat-jdbc-8.5.23.jar:na]  at
    org.apache.tomcat.jdbc.pool.PooledConnection.connect(PooledConnection.java:203)
    ~[tomcat-jdbc-8.5.23.jar:na]  at
    org.apache.tomcat.jdbc.pool.ConnectionPool.createConnection(ConnectionPool.java:735)
    ~[tomcat-jdbc-8.5.23.jar:na]  at
    org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:667)
    ~[tomcat-jdbc-8.5.23.jar:na]  at
    org.apache.tomcat.jdbc.pool.ConnectionPool.init(ConnectionPool.java:482)
    ~[tomcat-jdbc-8.5.23.jar:na]  at
    org.apache.tomcat.jdbc.pool.ConnectionPool.(ConnectionPool.java:154)
    ~[tomcat-jdbc-8.5.23.jar:na]  at
    org.apache.tomcat.jdbc.pool.DataSourceProxy.pCreatePool(DataSourceProxy.java:118)
    ~[tomcat-jdbc-8.5.23.jar:na]  at
    org.apache.tomcat.jdbc.pool.DataSourceProxy.createPool(DataSourceProxy.java:107)
    ~[tomcat-jdbc-8.5.23.jar:na]  at
    org.apache.tomcat.jdbc.pool.DataSourceProxy.getConnection(DataSourceProxy.java:131)
    ~[tomcat-jdbc-8.5.23.jar:na]  at
    org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)
    ~[spring-jdbc-4.3.13.RELEASE.jar:4.3.13.RELEASE]  at
    org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77)
    ~[spring-jdbc-4.3.13.RELEASE.jar:4.3.13.RELEASE]  ... 62 common frames
    omitted Caused by: java.nio.BufferUnderflowException: null    at
    java.nio.HeapByteBuffer.get(Unknown Source) ~[na:1.8.0_152]   at
    java.nio.ByteBuffer.get(Unknown Source) ~[na:1.8.0_152]   at
    oracle.net.ns.NIOAcceptPacket.readPayloadBuffer(NIOAcceptPacket.java:167)
    ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]     at
    oracle.net.ns.NIOPacket.readNIOPacket(NIOPacket.java:282)
    ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]     at
    oracle.net.ns.NSProtocolNIO.negotiateConnection(NSProtocolNIO.java:118)
    ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]     at
    oracle.net.ns.NSProtocol.connect(NSProtocol.java:317)
    ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]     at
    oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1438)
    ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]     at
    oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:518)
    ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]     at
    oracle.jdbc.driver.PhysicalConnection.connect(PhysicalConnection.java:688)
    ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]     at
    oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:39)
    ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]     at
    oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:691)
    ~[ojdbc8-12.2.0.1.jar:12.2.0.1.0]     at
    org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:310)
    ~[tomcat-jdbc-8.5.23.jar:na]  ... 72 common frames omitted</p>
  </blockquote>
  
  <p>If I switch to debug mode I get a little more details and exception happens right after:</p>
  
  <blockquote>
    <p>2018-03-01 15:34:21.435 DEBUG 44920 --- [           main]
    o.s.jdbc.datasource.DataSourceUtils      : Fetching JDBC Connection
    from DataSource 2018-03-01 15:34:21.446 DEBUG 44920 --- [<br>
    main] o.a.tomcat.jdbc.pool.PooledConnection    : Instantiating driver
    using class: oracle.jdbc.driver.OracleDriver
    [url=jdbc:oracle:thin:@//exa22-scan8.swift.corp:1500/cpmsdev_usr.swift.com]
    2018-03-01 15:34:21.447 DEBUG 44920 --- [           main]
    o.a.tomcat.jdbc.pool.ClassLoaderUtil     : Attempting to load
    class[oracle.jdbc.driver.OracleDriver] from
    sun.misc.Launcher$AppClassLoader@659e0bfd</p>
  </blockquote>
  
  <p>I'm using the same URL, service_name, and credentials to connect to DB in sqldeveloper and can confirm that that part is correct. I also tried options suggested in above links setting up</p>
  
  <pre><code>System.setProperty("oracle.net.tns_admin", "C:/ora12/client_1/network/admin");
  </code></pre>
  
  <p>and setting url @service_name with the same result</p>
  
  <p>I'm completely lost on what can be the reason for it - incorrect syntax or anything else? 
  Does anyone else have any suggestion what can cause it and what can be a possible solution?</p>
  
  <p>pom.xml dependecnies</p>
  
  <pre><code>&lt;dependencies&gt;
  &lt;dependency&gt;
    &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
    &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
  &lt;/dependency&gt;       
  &lt;dependency&gt;
    &lt;groupId&gt;com.oracle.ojdbc&lt;/groupId&gt;
    &lt;artifactId&gt;ojdbc8&lt;/artifactId&gt;
    &lt;version&gt;12.2.0.1&lt;/version&gt;
  &lt;/dependency&gt;
  &lt;/dependencies&gt;
  </code></pre>
  
  <p>Appreciate any suggestions or help on it!</p>