title: spring-boot datasource profiles w/ application.properties
body: <p><strong><em>Updated Question based upon feedback:</em></strong></p>
  
  <p>I have a spring-boot application that has three databases: H2 for integration testing, and Postgresql for qa &amp; production.   Since spring-boot creates a default datasource for you, I don't have anything defined for my integration tests.  I thought I would use application.properties to define my datasource connection values but I am not certain what is the best way to handle this.   </p>
  
  <p>I have two files:</p>
  
  <p><strong>src/main/resources/application.properties</strong></p>
  
  <pre><code>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
  </code></pre>
  
  <p><strong>src/main/resources/application-test.properties</strong></p>
  
  <pre><code>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
  </code></pre>
  
  <p>I used to run my tests with with gradle (using "gradle build test") or within IntelliJ.  I updated my gradle file to use:</p>
  
  <pre><code>task setTestEnv {
      run { systemProperty "spring.profiles.active", "test" }
  }
  </code></pre>
  
  <p>But when I run <strong>gradle clean build setTestEnv test</strong>   I get errors that seem to indicate the test is trying to connect to an actual Postgresql database:  </p>
  
  <pre><code>Caused by: org.postgresql.util.PSQLException: Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
      at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:138)
      at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:66)
      at org.postgresql.jdbc2.AbstractJdbc2Connection.&lt;init&gt;(AbstractJdbc2Connection.java:125)
      at org.postgresql.jdbc3.AbstractJdbc3Connection.&lt;init&gt;(AbstractJdbc3Connection.java:30)
      at org.postgresql.jdbc3g.AbstractJdbc3gConnection.&lt;init&gt;(AbstractJdbc3gConnection.java:22)
      at org.postgresql.jdbc4.AbstractJdbc4Connection.&lt;init&gt;(AbstractJdbc4Connection.java:32)
      at org.postgresql.jdbc4.Jdbc4Connection.&lt;init&gt;(Jdbc4Connection.java:24)
      at org.postgresql.Driver.makeConnection(Driver.java:393)
      at org.postgresql.Driver.connect(Driver.java:267)
      at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:278)
      at org.apache.tomcat.jdbc.pool.PooledConnection.connect(PooledConnection.java:182)
      at org.apache.tomcat.jdbc.pool.ConnectionPool.createConnection(ConnectionPool.java:701)
      at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:635)
      at org.apache.tomcat.jdbc.pool.ConnectionPool.init(ConnectionPool.java:486)
      at org.apache.tomcat.jdbc.pool.ConnectionPool.&lt;init&gt;(ConnectionPool.java:144)
      at org.apache.tomcat.jdbc.pool.DataSourceProxy.pCreatePool(DataSourceProxy.java:116)
      at org.apache.tomcat.jdbc.pool.DataSourceProxy.createPool(DataSourceProxy.java:103)
      at org.apache.tomcat.jdbc.pool.DataSourceProxy.getConnection(DataSourceProxy.java:127)
      at liquibase.integration.spring.SpringLiquibase.afterPropertiesSet(SpringLiquibase.java:288)
      ... 42 more
  Caused by: java.net.ConnectException: Connection refused
      at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
  </code></pre>
  
  <p>I haven't figured out how to set the default system.property == "test" within IntelliJ yet...</p>