title: How to make Spring Boot application run despite whether a datasource is available
body: <p>In my Spring Boot application, a datasource is configured. <code>application.properties</code> is like:</p>
  
  <pre><code>spring.datasource.url=jdbc:mysql://localhost/test_db
  spring.datasource.username=test
  spring.datasource.password=test
  </code></pre>
  
  <p>The application code looks like:</p>
  
  <pre><code>public class Foo {
      @Autowired
      private JdbcTemplate jdbcTemplate;
  
      private List&lt;String&gt; getDataFromDB(String user) {
          List&lt;String&gt; data = jdbcTemplate.query(
                      "SELECT ... FROM ...;", /* the detail ommited */);
          return data;
      }
  }
  </code></pre>
  
  <p>The code works fine. However, if the database server isn't available, Spring Boot would fail to start:</p>
  
  <pre><code>2018-01-17 14:03:30.310 ERROR o.a.tomcat.jdbc.pool.ConnectionPool     [182][main][][][] Unable to create initial connections of pool.
  com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
  
  The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
      ...
  2018-01-17 14:03:30.314  WARN o.h.e.jdbc.internal.JdbcServicesImpl    [204][main][][][] HHH000342: Could not obtain connection to query metadata : Communications link failure
  
  The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
  2018-01-17 14:03:30.318  WARN ationConfigEmbeddedWebApplicationContext[546][main][][][] Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
  2018-01-17 14:03:30.336 ERROR o.s.boot.SpringApplication              [827][main][][][] Application startup failed
  org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
      ...
  
  Process finished with exit code 1
  </code></pre>
  
  <p>I've omitted many lines of error messages.</p>
  
  <p>In my application, the database isn't necessary, it's only used for <em>improvement</em>. I would like to run the application even if the database isn't available, but be noticed such failure.</p>
  
  <p>How to achieve this?</p>