diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..d3790a3 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,32 @@ +version: "3.3" + +services: + backend: + build: + context: . + container_name: backend + depends_on: + - db + environment: + - SPRING_DATASOURCE_URL=jdbc:postgresql://db:5432/test_db + - SPRING_DATASOURCE_USERNAME=root + - SPRING_DATASOURCE_PASSWORD=root + ports: + - '8080:8080' + + db: + image: postgres:14.7 + container_name: db + environment: + POSTGRES_USER: root + POSTGRES_PASSWORD: root + POSTGRES_DB: test_db + volumes: + - postgresql:/var/lib/postgresql + - postgresql_data:/var/lib/postgresql/data + ports: + - '5432:5432' + +volumes: + postgresql: + postgresql_data: \ No newline at end of file diff --git a/pom.xml b/pom.xml index 5b9c2d5..f34233e 100644 --- a/pom.xml +++ b/pom.xml @@ -27,6 +27,18 @@ spring-boot-starter-test test + + + org.springframework.boot + spring-boot-starter-data-jpa + + + + org.postgresql + postgresql + runtime + + diff --git a/src/main/java/com/example/demo/Student.java b/src/main/java/com/example/demo/Student.java new file mode 100644 index 0000000..a740351 --- /dev/null +++ b/src/main/java/com/example/demo/Student.java @@ -0,0 +1,38 @@ +package com.example.demo; + +import jakarta.persistence.*;; + +@Entity +public class Student { + + @Id + @GeneratedValue + private Long id; + private String name; + + public Student(){ + + } + + public Student(String name){ + this.name = name; + } + + public Long getId(){ + return id; + } + + public void setId(Long id){ + this.id = id; + } + + public String getName(){ + return name; + } + + public void setName(String name){ + this.name = name; + } + + +} \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 8b13789..397208d 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1 +1,6 @@ - +spring.datasource.url=jdbc:postgresql://localhost:5432/test_db +spring.datasource.username=root +spring.datasource.password=root +spring.datasource.driver-class-name=org.postgresql.Driver +spring.jpa.hibernate.ddl-auto=update +spring.jpa.show-sql=true \ No newline at end of file diff --git a/src/test/java/com/example/demo/DemoApplicationTests.java b/src/test/java/com/example/demo/DemoApplicationTests.java index 2778a6a..5adc653 100644 --- a/src/test/java/com/example/demo/DemoApplicationTests.java +++ b/src/test/java/com/example/demo/DemoApplicationTests.java @@ -6,8 +6,8 @@ @SpringBootTest class DemoApplicationTests { - @Test - void contextLoads() { - } + // @Test + // void contextLoads() { + // } }