1

Springboot Version 2.0.6.RELEASE +JPA

Why it is trying to create Datasource bean.

Properties for Hibernate and Oracle

spring.datasource.driverClassName=oracle.jdbc.driver.OracleDriver
spring.datasource.url=jdbc:oracle:thin:@//earth-db-11:5121/stardev
spring.datasource.username=ops$abcdefg
spring.datasource.password=mypassword
spring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialect

What Have i tried

 - @SpringBootApplication( exclude={DataSourceAutoConfiguration.class})
 - @EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
 - Create New @Configuration Datasouce @bean ,with JPA properties and Create Datasoucetest class with in memory DB.
- mvn clean instal -DskipTests --- **this works fine but i want my others tests to run.**

Dependency Included

    <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-data-jpa</artifactId>
            </dependency>
            <dependency>
                <groupId>com.oracle</groupId>
                <artifactId>ojdbc7</artifactId>
                <version>${ojdbc.version}</version>
     </dependency>

Error log

[HikariDataSource]-[110 ]-HikariPool-1 - Starting... 
[2018-11-27T16:30:43,541+0530]-[ERROR]-[realmId=,tid=]-[HikariPool]-[567 ]-HikariPool-1 - Exception during pool initialization. java.sql.SQLRecoverableException: IO Error: The Network Adapter could not establish the connection
    at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:743)
    at oracle.jdbc.driver.PhysicalConnection.connect(PhysicalConnection.java:666)
    at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)
    at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:566)
    at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:117)
    at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:123)
    at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:365)
    at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:194)
    at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:460)
    at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:534)
    at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115)
    at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112)
    at com.zaxxer.hikari.HikariDataSource$$FastClassBySpringCGLIB$$eeb1ae86.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:746)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
    at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:136)
    at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:124)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
    at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688)
    at com.zaxxer.hikari.HikariDataSource$$EnhancerBySpringCGLIB$$c1fb58c0.getConnection(<generated>)
    at org.springframework.jdbc.datasource.DataSourceUtils.fetchConnection(DataSourceUtils.java:151)
    at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:115)
    at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:78)
    at org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:319)
    at org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:356)
    at org.springframework.boot.autoconfigure.orm.jpa.DatabaseLookup.getDatabase(DatabaseLookup.java:72)
    at org.springframework.boot.autoconfigure.orm.jpa.JpaProperties.determineDatabase(JpaProperties.java:166)
    at org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.jpaVendorAdapter(JpaBaseConfiguration.java:111)
    at org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration$$EnhancerBySpringCGLIB$$c529ad27.CGLIB$jpaVendorAdapter$6(<generated>)
    at org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration$$EnhancerBySpringCGLIB$$c529ad27$$FastClassBySpringCGLIB$$f6c0d4d0.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:365)
    at org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration$$EnhancerBySpringCGLIB$$c529ad27.jpaVendorAdapter(<generated>)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:583)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1246)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1096)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:535)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495)
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)

Posts that i have referred to

Unable to connect to oracle database.It says "Unable to determine jdbc url from datasource"

org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set

Cannot load configuration class in Spring with Oracle db connection

hibernate dialect for oracle 12c

Community
  • 1
  • 1
tharani dharan
  • 425
  • 3
  • 8
  • 18
  • Could you please also check next things to clarify this problem: * The database isn't running * You got the URL wrong * There is a firewall in the way. – Ishikawa Yoshi Nov 27 '18 at 11:36
  • My Database is hosted in AWS and hence wont be able to reach the DB host. Is there any way it does not create the Datasource bean at all ? – tharani dharan Nov 27 '18 at 11:54
  • can you connect to database via sqlplus? by using next command: sqlplus username/password@host:port/service – Ishikawa Yoshi Nov 27 '18 at 12:02
  • so the setup is like this . My App is in 1 AWS account , and my DB is another AWS account , there is a bridge create , Where DB host will accept requests only from app aws host. So when i code in my local i dont want the DB Bean to be created and test to be run . – tharani dharan Nov 27 '18 at 12:09

3 Answers3

1

I can show you my configuration which works for me it checked few minutes before, only difference is oracle driver.

spring-boot v.2.0.1.RELEASE

pom.xml

<dependency>
   <groupId>oracle</groupId>
   <artifactId>ojdbc6</artifactId>
   <version>11.2.0.1</version>
</dependency>

OracleConfiguration

@Configuration
@ConfigurationProperties
public class OracleConfiguration {

    private static Logger log = LoggerFactory.getLogger(OracleConfiguration.class);

    @Value("${oracle.username}")
    private String username;
    @Value("${oracle.password}")
    private String password;
    @Value("${oracle.url}")
    private String url;

    @Bean
    DataSource dataSource() throws SQLException{
        log.info("Init production profile for OracleConfiguration");
        OracleDataSource dataSource = new OracleDataSource();
        dataSource.setUser(username);
        dataSource.setPassword(password);
        dataSource.setURL(url);
        dataSource.setImplicitCachingEnabled(true);
        dataSource.setFastConnectionFailoverEnabled(true);
        return dataSource;
    }
}

application.properties

oracle.username=username
oracle.password=password
oracle.url=jdbc:oracle:thin:@//db.yourdomain.com:1524/DB
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver
spring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialect

You can check this answer https://stackoverflow.com/a/12574926/1063509

  • The database isn't running
  • You got the URL wrong
  • There is a firewall in the way.
Ishikawa Yoshi
  • 1,779
  • 8
  • 22
  • 43
  • I Used H2 In-Memory DB and established the connection to it for my tests. This way Problem will be resolved for local deployment. – tharani dharan Sep 11 '19 at 10:55
0

Your URL has irrelevant double slash (when you removed user & password),change to:

spring.datasource.url=jdbc:oracle:thin:@earth-db-11:5121/stardev
Ori Marko
  • 56,308
  • 23
  • 131
  • 233
0

Hi try change your password in mysql workbench or toad for mysql.

Danker
  • 1