title: Spring Boot Connect to mysql docker
body: <p>I have spun up the <code>mysql</code> docker image.</p>
  
  <p>From <code>docker ps</code>:</p>
  
  <p><code>bcb0a900b693        mysql:latest        "docker-entrypoint..."   5 hours ago         Up About an hour    0.0.0.0:3306-&gt;3306/tcp   chrisbolton</code></p>
  
  <p>I have created a basic <code>spring boot</code> project where I have created a simple class.</p>
  
  <pre><code>@SpringBootApplication
  @RestController
  public class ChrisboltonServiceApplication {
  
  public static void main(String[] args) {
      SpringApplication.run(ChrisboltonServiceApplication.class, args);
  }
  
  @Autowired
  private JdbcTemplate jdbcTemplate;
  
  @RequestMapping("/hello")
  public String sayHello(){
      return "Hello";
  }
  
  @RequestMapping(path="/blogs")
  public @ResponseBody Iterable&lt;ChrisBolton&gt; getAllUsers() {
      List&lt;ChrisBolton&gt; result = jdbcTemplate.query(
              "SELECT * FROM blog",
              (rs, rowNum) -&gt; new ChrisBolton(rs.getString("author"), 
                                                 rs.getString("title"), 
                                                 rs.getString("content"), 
                                                 rs.getDate("date"))
      );
  
      return result;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>I have placed my configuration in my <code>application.properties</code></p>
  
  <pre><code>spring.main.banner-mode=off
  
  spring.datasource.url=jdbc:mysql://localhost:3306
  spring.datasource.username=root
  spring.datasource.password=opening
  spring.datasource.driver-class-name=com.mysql.jdbc.Driver
  </code></pre>
  
  <p>When I start my app, I am able to hit <code>localhost:8080/hello</code> which returns <code>Hello!</code></p>
  
  <p>When I hit <code>localhost:8080/blogs</code>, I get this error</p>
  
  <p><code>java.sql.SQLException: No database selected</code></p>
  
  <p>So I guess I don't understand how the <code>autowired</code> is completely working.</p>
  
  <p>I have tried looking into <code>beans</code> or maybe using the <code>Connection</code> class. But what is the correct <code>Spring Boot</code> way of connecting to my <code>mysql</code> instance?</p>