diff --git a/samples/spring-postgres/backend/Dockerfile b/samples/spring-postgres/backend/Dockerfile
index 10e0920..949dd0a 100755
--- a/samples/spring-postgres/backend/Dockerfile
+++ b/samples/spring-postgres/backend/Dockerfile
@@ -1,12 +1,20 @@
-FROM maven:3.5-jdk-9 AS build
-COPY pom.xml .
-RUN mvn --batch-mode dependency:resolve
-COPY . .
-RUN mvn --batch-mode package
-RUN cp target/*jar target/app.jar
+FROM maven:3.6.3-jdk-11 AS builder
+WORKDIR /workdir/server
+COPY pom.xml /workdir/server/pom.xml
+RUN mvn dependency:go-offline
+
+COPY src /workdir/server/src
+RUN mvn install
+RUN mkdir -p target/depency
+WORKDIR /workdir/server/target/dependency
+RUN jar -xf ../*.jar
+
+FROM openjdk:11-jre-slim
-FROM openjdk:9-jre
EXPOSE 8080
VOLUME /tmp
-COPY --from=build target/app.jar app.jar
-ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
+ARG DEPENDENCY=/workdir/server/target/dependency
+COPY --from=builder ${DEPENDENCY}/BOOT-INF/lib /app/lib
+COPY --from=builder ${DEPENDENCY}/META-INF /app/META-INF
+COPY --from=builder ${DEPENDENCY}/BOOT-INF/classes /app
+ENTRYPOINT ["java","-cp","app:app/lib/*","com.company.project.Application"]
\ No newline at end of file
diff --git a/samples/spring-postgres/backend/pom.xml b/samples/spring-postgres/backend/pom.xml
index aeef767..b0471a1 100755
--- a/samples/spring-postgres/backend/pom.xml
+++ b/samples/spring-postgres/backend/pom.xml
@@ -14,24 +14,37 @@
org.springframework.boot
spring-boot-starter-parent
- 2.0.3.RELEASE
+ 2.2.5.RELEASE
UTF-8
UTF-8
- 1.8
+ 11
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+ org.springframework.boot
+ spring-boot-starter-freemarker
+
org.springframework.boot
spring-boot-starter-jersey
org.springframework.boot
- spring-boot-starter-web
+ spring-boot-starter-data-jpa
+
+
+ org.postgresql
+ postgresql
+ runtime
org.springframework.session
@@ -40,26 +53,22 @@
org.springframework.boot
spring-boot-devtools
-
-
- org.springframework.boot
- spring-boot-starter-freemarker
+ runtime
+ true
org.springframework.boot
spring-boot-starter-test
test
-
-
- org.projectlombok
- lombok
-
-
- javax.xml.bind
- jaxb-api
- 2.3.0
+
+
+ org.junit.vintage
+ junit-vintage-engine
+
+
+
diff --git a/samples/spring-postgres/backend/src/main/java/com/company/project/controllers/HomeController.java b/samples/spring-postgres/backend/src/main/java/com/company/project/controllers/HomeController.java
index 966839d..c23d706 100755
--- a/samples/spring-postgres/backend/src/main/java/com/company/project/controllers/HomeController.java
+++ b/samples/spring-postgres/backend/src/main/java/com/company/project/controllers/HomeController.java
@@ -1,15 +1,22 @@
package com.company.project.controllers;
+import com.company.project.entity.Greeting;
+import com.company.project.repository.GreetingRepository;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestParam;
@Controller
public class HomeController {
+ @Autowired
+ private GreetingRepository repository;
+
@GetMapping("/")
public String showHome(String name, Model model) {
+ Greeting dockerGreeting = repository.findById(1).orElse(new Greeting("Not Found 😕"));
+ model = model.addAttribute("name", dockerGreeting.getName());
return "home";
}
diff --git a/samples/spring-postgres/backend/src/main/java/com/company/project/entity/Greeting.java b/samples/spring-postgres/backend/src/main/java/com/company/project/entity/Greeting.java
new file mode 100644
index 0000000..67c1079
--- /dev/null
+++ b/samples/spring-postgres/backend/src/main/java/com/company/project/entity/Greeting.java
@@ -0,0 +1,57 @@
+package com.company.project.entity;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+@Entity
+@Table(name = "GREETINGS")
+public class Greeting {
+
+ @Id
+ private int id;
+ private String name;
+
+ public Greeting() {
+ }
+
+ public Greeting(String name) {
+ this.name = name;
+ }
+
+ public Greeting(int id, String name) {
+ this.id = id;
+ this.name = name;
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ Greeting greeting = (Greeting) o;
+
+ return name.equals(greeting.name);
+ }
+
+ @Override
+ public int hashCode() {
+ return name.hashCode();
+ }
+}
diff --git a/samples/spring-postgres/backend/src/main/java/com/company/project/repository/GreetingRepository.java b/samples/spring-postgres/backend/src/main/java/com/company/project/repository/GreetingRepository.java
new file mode 100644
index 0000000..8927337
--- /dev/null
+++ b/samples/spring-postgres/backend/src/main/java/com/company/project/repository/GreetingRepository.java
@@ -0,0 +1,9 @@
+package com.company.project.repository;
+
+import com.company.project.entity.Greeting;
+import org.springframework.data.repository.CrudRepository;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public interface GreetingRepository extends CrudRepository {
+}
diff --git a/samples/spring-postgres/backend/src/main/resources/application.properties b/samples/spring-postgres/backend/src/main/resources/application.properties
index 8b13789..e911c04 100755
--- a/samples/spring-postgres/backend/src/main/resources/application.properties
+++ b/samples/spring-postgres/backend/src/main/resources/application.properties
@@ -1 +1,11 @@
+spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
+spring.jpa.hibernate.ddl-auto=none
+spring.jpa.hibernate.show-sql=true
+spring.datasource.url=jdbc:postgresql://db:5432/${POSTGRES_DB}
+spring.datasource.username=postgres
+spring.datasource.password=${POSTGRES_PASSWORD:db-wrz2z}
+spring.datasource.initialization-mode=always
+spring.datasource.initialize=true
+spring.datasource.schema=classpath:/schema.sql
+spring.datasource.continue-on-error=true
diff --git a/samples/spring-postgres/backend/src/main/resources/data.sql b/samples/spring-postgres/backend/src/main/resources/data.sql
new file mode 100644
index 0000000..122079f
--- /dev/null
+++ b/samples/spring-postgres/backend/src/main/resources/data.sql
@@ -0,0 +1 @@
+INSERT INTO GREETINGS(name) values ('Docker');
diff --git a/samples/spring-postgres/backend/src/main/resources/schema.sql b/samples/spring-postgres/backend/src/main/resources/schema.sql
new file mode 100644
index 0000000..bd40371
--- /dev/null
+++ b/samples/spring-postgres/backend/src/main/resources/schema.sql
@@ -0,0 +1,4 @@
+CREATE TABLE IF NOT EXISTS GREETINGS (
+ id serial PRIMARY KEY,
+ name varchar(50) NOT NULL
+);
diff --git a/samples/spring-postgres/backend/src/main/resources/templates/home.ftl b/samples/spring-postgres/backend/src/main/resources/templates/home.ftlh
similarity index 86%
rename from samples/spring-postgres/backend/src/main/resources/templates/home.ftl
rename to samples/spring-postgres/backend/src/main/resources/templates/home.ftlh
index daba182..42d0c29 100755
--- a/samples/spring-postgres/backend/src/main/resources/templates/home.ftl
+++ b/samples/spring-postgres/backend/src/main/resources/templates/home.ftlh
@@ -5,5 +5,5 @@
- Hello from Docker!
+ Hello from ${name}!
diff --git a/samples/spring-postgres/docker-compose.yaml b/samples/spring-postgres/docker-compose.yaml
index 307a6a7..d6cb620 100644
--- a/samples/spring-postgres/docker-compose.yaml
+++ b/samples/spring-postgres/docker-compose.yaml
@@ -4,6 +4,10 @@ services:
build: backend
ports:
- 80:8080
+ environment:
+ POSTGRES_DB: example
+ networks:
+ - spring-postges
db:
environment:
POSTGRES_DB: example
@@ -14,8 +18,12 @@ services:
- db-password
volumes:
- db-data:/var/lib/postgresql/data
+ networks:
+ - spring-postges
volumes:
db-data: {}
secrets:
db-password:
file: db/password.txt
+networks:
+ spring-postges: {}