2

We use hierarchically organised Spring boot property files in our application. For example,

Our application.properties will just contain a single line.

spring.profiles.include = logging, kafka, oracle, misc

Where all the values separated by comma here are other property files (namely application-logging.properties and so on) that it's referring to (We chose this for reusability in different environments)

And I have another properties file application-h2.properties that can be included while testing. So while I test, my application.properties will look like this.

spring.profiles.include = logging, kafka, h2, misc

The problem that's been bugging me here is that my application is always considering h2 database when it starts up, although I include oracle.

Here's how my application-oracle.properties file looks.

spring.datasource.url=${ORACLE_URL}
spring.datasource.username=${ORACLE_USERNAME}
spring.datasource.password=${ORACLE_PASSWORD}
spring.jpa.show-sql=true
spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
spring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialect
spring.jpa.properties.hibernate.jdbc.time_zone = UTC

The only way I have to get Oracle enabled is that I have remove the h2 properties file, and also remove the h2 dependency from the gradle build file.

Appreciate your help!

Aryan Venkat
  • 679
  • 1
  • 10
  • 34
  • 1
    If I'm not mistaken, Spring boot will use H2 by default if it can't find any configuration for the other datasource. Are you sure that your `application-oracle.properties` contains the properties necessary to configure your datasource? – g00glen00b Feb 11 '19 at 08:17
  • @g00glen00b Yes it does. Edited my question with the contents of the properties file. – Aryan Venkat Feb 11 '19 at 09:59
  • this does not seems to me like a problem with the property file itself. I would look into the loading @Configuration class, if given profile loads given file, etc... There may be a copypaste error or typo of some sort. – jan.zanda Feb 11 '19 at 10:34
  • @jan.zanda I use `@SpringBootApplication` annotation on my start up class which uses `@EnableAutoConfiguration` under the hood. I have no special config class for oracle or h2. – Aryan Venkat Feb 11 '19 at 11:05
  • If I am not wrong, is because of the dependency I had the same problem, use testCompile for the h2 dependecy (if you are using gradle, I think it should work). Check this http://www.springboottutorial.com/spring-boot-and-h2-in-memory-database – agata Feb 11 '19 at 12:43
  • Please add the dependency as well. (the needed part, gradle or maven) – agata Feb 11 '19 at 12:46
  • @agata I've been using the same: `testCompile group: 'com.h2database', name: 'h2', version: '1.3.148'` – Aryan Venkat Feb 11 '19 at 12:52
  • Hmm..then maybe one way to get rid of this is: use only one application.properties for db. (E.g. in my project I have oracle and mysql db config in application.properties and then for the test, the same application.properties is overwritten with h2 config) – agata Feb 11 '19 at 13:01

0 Answers0