| Line 1: |
Line 1: |
| − | == Create microservices == | + | ==Create microservices== |
| | <syntaxhighlight lang="java"> | | <syntaxhighlight lang="java"> |
| | import java.util.Arrays; | | import java.util.Arrays; |
| Line 145: |
Line 145: |
| | | | |
| | ===/src/main/resources/application.properties=== | | ===/src/main/resources/application.properties=== |
| | + | |
| | + | ==== h2 Database ==== |
| | <syntaxhighlight lang="java"> | | <syntaxhighlight lang="java"> |
| | spring.datasource.url=jdbc:h2:mem:testdb | | spring.datasource.url=jdbc:h2:mem:testdb |
| Line 151: |
Line 153: |
| | spring.jpa.defer-datasource-initialization=true | | spring.jpa.defer-datasource-initialization=true |
| | </syntaxhighlight>database will be accessible via http://localhost:8080/h2-console | | </syntaxhighlight>database will be accessible via http://localhost:8080/h2-console |
| | + | |
| | + | ==== Docker MySQL ==== |
| | + | <syntaxhighlight lang="java"> |
| | + | #spring.datasource.url=jdbc:h2:mem:testdb |
| | + | |
| | + | spring.jpa.hibernate.ddl-auto=update |
| | + | spring.datasource.url=jdbc:mysql://localhost:3306/courses |
| | + | spring.datasource.username=courses-user |
| | + | spring.datasource.password=dummycourses |
| | + | spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL57Dialect |
| | + | |
| | + | #courses-user@localhost:3306 |
| | + | </syntaxhighlight>Start MySQL Docker container<syntaxhighlight lang="bash"> |
| | + | docker run --detach --env MYSQL_ROOT_PASSWORD=dummypassword --env MYSQL_USER=courses-user --env MYSQL_PASSWORD=dummycourses --env MYSQL_DATABASE=courses --name mysql --publish 3306:3306 mysql:5.7 |
| | + | </syntaxhighlight>mysqlsh commands<syntaxhighlight lang="mysql"> |
| | + | mysqlsh |
| | + | \connect courses-user@localhost:3306 |
| | + | \sql |
| | + | use courses |
| | + | select * from course; |
| | + | \quit |
| | + | </syntaxhighlight><syntaxhighlight lang="bash"> |
| | + | # Stop MySQL container |
| | + | docker container ls |
| | + | docker container stop ID |
| | + | </syntaxhighlight> |
| | | | |
| | ===/src/main/java/com/in28minutes/learnspringboot/courses/bean/Course.java=== | | ===/src/main/java/com/in28minutes/learnspringboot/courses/bean/Course.java=== |