spring-boot datasource profiles w/ application.properties -


updated question based upon feedback:

i have spring-boot application has 3 databases: h2 integration testing, , postgresql qa & production. since spring-boot creates default datasource you, don't have defined integration tests. thought use application.properties define datasource connection values not best way handle this.

i have 2 files:

src/main/resources/application.properties

spring.profiles.active=production appname = myproduct serverport=9001  spring.datasource.url=jdbc:postgresql://localhost/mydatabase spring.datasource.username=user spring.datasource.password=password spring.datasource.driverclassname=org.postgresql.driver  spring.jpa.hibernate.hbm2ddl.auto=update spring.jpa.hibernate.ejb.naming_strategy=org.hibernate.cfg.ejb3namingstrategy spring.jpa.hibernate.show_sql=true spring.jpa.hibernate.format_sql=true spring.jpa.hibernate.use_sql_comments=false spring.jpa.hibernate.type=all spring.jpa.hibernate.disableconnectiontracking=true spring.jpa.hibernate.default_schema=dental 

src/main/resources/application-test.properties

spring.profiles.active=test serverport=9002  spring.datasource.url = jdbc:h2:~/testdb spring.datasource.username = sa spring.datasource.password =  spring.datasource.driverclassname = org.h2.driver  liquibase.changelog=classpath:/db/changelog/db.changelog-master.sql 

i used run tests with gradle (using "gradle build test") or within intellij. updated gradle file use:

task settestenv {     run { systemproperty "spring.profiles.active", "test" } } 

but when run gradle clean build settestenv test errors seem indicate test trying connect actual postgresql database:

caused by: org.postgresql.util.psqlexception: connection refused. check hostname , port correct , postmaster accepting tcp/ip connections.     @ org.postgresql.core.v3.connectionfactoryimpl.openconnectionimpl(connectionfactoryimpl.java:138)     @ org.postgresql.core.connectionfactory.openconnection(connectionfactory.java:66)     @ org.postgresql.jdbc2.abstractjdbc2connection.<init>(abstractjdbc2connection.java:125)     @ org.postgresql.jdbc3.abstractjdbc3connection.<init>(abstractjdbc3connection.java:30)     @ org.postgresql.jdbc3g.abstractjdbc3gconnection.<init>(abstractjdbc3gconnection.java:22)     @ org.postgresql.jdbc4.abstractjdbc4connection.<init>(abstractjdbc4connection.java:32)     @ org.postgresql.jdbc4.jdbc4connection.<init>(jdbc4connection.java:24)     @ org.postgresql.driver.makeconnection(driver.java:393)     @ org.postgresql.driver.connect(driver.java:267)     @ org.apache.tomcat.jdbc.pool.pooledconnection.connectusingdriver(pooledconnection.java:278)     @ org.apache.tomcat.jdbc.pool.pooledconnection.connect(pooledconnection.java:182)     @ org.apache.tomcat.jdbc.pool.connectionpool.createconnection(connectionpool.java:701)     @ org.apache.tomcat.jdbc.pool.connectionpool.borrowconnection(connectionpool.java:635)     @ org.apache.tomcat.jdbc.pool.connectionpool.init(connectionpool.java:486)     @ org.apache.tomcat.jdbc.pool.connectionpool.<init>(connectionpool.java:144)     @ org.apache.tomcat.jdbc.pool.datasourceproxy.pcreatepool(datasourceproxy.java:116)     @ org.apache.tomcat.jdbc.pool.datasourceproxy.createpool(datasourceproxy.java:103)     @ org.apache.tomcat.jdbc.pool.datasourceproxy.getconnection(datasourceproxy.java:127)     @ liquibase.integration.spring.springliquibase.afterpropertiesset(springliquibase.java:288)     ... 42 more caused by: java.net.connectexception: connection refused     @ java.net.abstractplainsocketimpl.doconnect(abstractplainsocketimpl.java:339) 

i haven't figured out how set default system.property == "test" within intellij yet...

see section 21.3 of spring boot documentation. section describes how define profile specific property files use format application-{profile}.properties. can isolate properties on per profile basis.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -