I am trying to configure multi deployment environment for my web application using Spring Boot with Maven. Created several .properties files under src/main/resources/config. db-dev.properties and db-prod.properties consist of db specific information:
db.url=jdbc:oracle:thin:@ldap://dev.com/risstg3,
db.username=owner
db.password=godzilla
In the same directory I also have application.properties which reads in the variables defined in these db property files
#database info
spring.datasource.driverClassName=oracle.jdbc.OracleDriver
spring.datasource.url=${db.url}
spring.datasource.username=${db.username}
spring.datasource.password=${db.password}
#hibernate config
spring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialect
Multiple profiles are set up in my pom:
<profiles>
<profile>
<id>dev</id>
<properties>
<env>dev</env>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<env>prod</env>
</properties>
</profile>
</profiles>
<build>
<filters>
<filter>src/main/resources/config/db-${env}.properties</filter>
</filters>
<resources>
<resource>
<directory>src/main/resources/config</directory>
<filtering>true</filtering>
</resource>
</resources>
All other configuration is taken care of by Spring Boot with @SpringBootApplication annotation in my application class.
Then I built the war by specifying profile using -P option, e.g. mvn install -Pprod
. However I failed to deploy it with tomcat on local machine due to the following error:
SEVERE: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/ristoreService]]
Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
I thought I set 'hibernate.dialect' in application.properties with spring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialect
Based on this thread, this error may not necessarily have to do with hibernate dialect. You may see it if the db connection is not successful. What did I miss? Is there a way to tell whether the war is created with the correct profile and whether the variables defined in db-{dev}.properties are picked up?