Skip to content

Commit 61064a2

Browse files
committed
JPA and Docker Compose
MySQL Docker image in docker-compose and spring configs in application.yml
1 parent f184987 commit 61064a2

File tree

6 files changed

+55
-45
lines changed

6 files changed

+55
-45
lines changed

pom.xml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,19 @@
1717
<java.version>21</java.version>
1818
</properties>
1919
<dependencies>
20+
<dependency>
21+
<groupId>com.mysql</groupId>
22+
<artifactId>mysql-connector-j</artifactId>
23+
<scope>runtime</scope>
24+
</dependency>
25+
<dependency>
26+
<groupId>org.springframework.boot</groupId>
27+
<artifactId>spring-boot-starter-data-jpa</artifactId>
28+
</dependency>
2029
<dependency>
2130
<groupId>org.springframework.boot</groupId>
2231
<artifactId>spring-boot-starter-web</artifactId>
2332
</dependency>
24-
2533
<dependency>
2634
<groupId>org.springframework.boot</groupId>
2735
<artifactId>spring-boot-devtools</artifactId>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.springboot.Control;
2+
3+
import org.springframework.data.jpa.repository.JpaRepository;
4+
5+
import com.springboot.Entidades.Customer;
6+
7+
public interface CustomerRepository
8+
extends JpaRepository<Customer, Integer>{
9+
10+
11+
}

src/main/java/com/springboot/Customer.java renamed to src/main/java/com/springboot/Entidades/Customer.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
1-
package com.springboot;
1+
package com.springboot.Entidades;
22

3+
import jakarta.persistence.Entity;
4+
import jakarta.persistence.GeneratedValue;
5+
import jakarta.persistence.GenerationType;
6+
import jakarta.persistence.Id;
7+
import jakarta.persistence.SequenceGenerator;
8+
9+
@Entity
310
public class Customer {
411

12+
@Id
13+
@GeneratedValue(
14+
15+
strategy = GenerationType.IDENTITY
16+
17+
)
518
private Integer id;
619
private String name;
720
private String email;
Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
package com.springboot;
22

3-
import java.util.List;
4-
53
import org.springframework.boot.SpringApplication;
64
import org.springframework.boot.autoconfigure.SpringBootApplication;
7-
import org.springframework.web.bind.annotation.GetMapping;
85
import org.springframework.web.bind.annotation.RestController;
96

107
@SpringBootApplication
@@ -17,31 +14,4 @@ public static void main(String[] args){
1714

1815
}
1916

20-
@GetMapping("/")
21-
public GreetResponse greet(){
22-
23-
return new GreetResponse
24-
(
25-
"Hello",
26-
List.of("Javascript", "Java", "Python"),
27-
new Person("Davi", 21, 0.1)
28-
);
29-
30-
}
31-
32-
record Person(String name, int age, double savings){};
33-
34-
record GreetResponse(String greet, List<String> favProgrammingLanguages, Person person){
35-
36-
public GreetResponse(String greet, List<String> favProgrammingLanguages, Person person){
37-
38-
this.greet = greet;
39-
this.favProgrammingLanguages = favProgrammingLanguages;
40-
this.person = person;
41-
42-
}
43-
44-
45-
}
46-
4717
}
Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
11
services:
22
db:
3-
image: mysql:latest
3+
container_name: springboot_db
4+
image: mysql
45
restart: unless-stopped
56
environment:
67
MYSQL_ROOT_PASSWORD: Bombinhas123@
7-
MYSQL_DATABASE: davi_home
8-
MYSQL_TCP_PORT: 3306
98
ports:
10-
8888: 8888
11-
expose:
12-
3306
9+
- "8080:3306"
1310

14-
15-
adminer:
16-
image: adminer
17-
restart: unless-stopped
18-
ports:
19-
- 8888:8888"
11+

src/main/resources/application.yml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,18 @@
11
server:
2-
port: 3000
2+
port: 3030
3+
4+
spring:
5+
datasource:
6+
url: jdbc:mysql://localhost:8080/customer
7+
username: root
8+
password: Bombinhas123@
9+
driver-class-name: com.mysql.cj.jdbc.Driver
10+
11+
jpa:
12+
database-platform: org.hibernate.dialect.MySQLDialect
13+
hibernate:
14+
ddl-auto: update
15+
show-sql: true
16+
17+
application:
18+
name: SPRING_PROJECT

0 commit comments

Comments
 (0)