Welcome back friends! In the previous post we have seen what is Richardson Maturity Model Session20 In past post we have used H2 In memory database for Database examples. In this post I will going to migrate DB configuration to MySQL DB. Let see how to change the configuration.
In our previous example ,we have used application.properties as configuration files. From now on I would like to use application.yml file as configuration file because now days most of the companies using .yml file for their Project configuration. lets make familiar with yml file.
Following is our app application.yml config file.
server: port: 8082 spring: datasource: url: jdbc:mysql://localhost:3307/billingdb driverClassName: com.mysql.cj.jdbc.Driver username: suresh password: suresh123$$ jpa: show-sql: true hibernate: ddl-auto: update
In the above application.yml file I have added our application config and MySQL config information. In the case of yml file we need to use : for each sub attribute. We don’t have to repeat the attribute again and again.
For example. Following way we need to use properties file. when you closely look at below property file configuration, we are using spring and datasource attribute again and again but in the case of yml we don’t have to do that.
After defining config information for MySQL, you need to add following artifact for connecting MySQL DB
<dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency>
Once you added this Artifact,when you start the application, spring boot find the MySql jars and connect with MySql Database.
Thats it MySql configuration is completed.
Download full source code from following GitHub link:
For better understanding please watch full video
Buy our hygiene Napkin. Our Napkins are chemical-free napkin and it has three categories.
Wings Napkin – This napkin wrapped around pure cotton cloth
Maternity Napkin for new Moms