Update Spring Boot and Mysql version for react-java-mysql sample
Signed-off-by: Guillaume Lours <guillaume.lours@docker.com>master
parent
0b40d180de
commit
d7d79e436f
@ -1,11 +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
|
||||
|
||||
FROM openjdk:9-jre
|
||||
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
|
||||
|
||||
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"]
|
@ -1,16 +1,21 @@
|
||||
package com.company.project.controllers;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import com.company.project.entity.Greeting;
|
||||
import com.company.project.repository.GreetingRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@Controller
|
||||
@RestController
|
||||
public class HomeController {
|
||||
|
||||
@Autowired
|
||||
private GreetingRepository repository;
|
||||
|
||||
@GetMapping("/")
|
||||
public String showHome(String name, Model model) {
|
||||
return "home";
|
||||
public Greeting showHome(String name, Model model) {
|
||||
return repository.findById(1).orElse(new Greeting("Not Found 😕"));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,61 @@
|
||||
package com.company.project.entity;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.GeneratedValue;
|
||||
|
||||
@Entity
|
||||
@Table(name = "greetings")
|
||||
public class Greeting {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private int id;
|
||||
@Column(nullable = false)
|
||||
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();
|
||||
}
|
||||
}
|
@ -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<Greeting, Integer> {
|
||||
}
|
@ -1 +1,12 @@
|
||||
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL8Dialect
|
||||
spring.jpa.hibernate.ddl-auto=none
|
||||
spring.jpa.hibernate.show-sql=true
|
||||
|
||||
|
||||
spring.datasource.url=jdbc:mysql://${MYSQL_HOST:db}:3306/example
|
||||
spring.datasource.username=root
|
||||
spring.datasource.password=${MYSQL_PASSWORD:db-57xsl}
|
||||
spring.datasource.initialization-mode=always
|
||||
spring.datasource.initialize=true
|
||||
spring.datasource.schema=classpath:/schema.sql
|
||||
spring.datasource.continue-on-error=true
|
||||
|
@ -0,0 +1 @@
|
||||
INSERT INTO example.greetings(name) values ('Docker');
|
@ -0,0 +1,5 @@
|
||||
CREATE TABLE IF NOT EXISTS example.greetings (
|
||||
id INTEGER AUTO_INCREMENT,
|
||||
name varchar(50) NOT NULL,
|
||||
PRIMARY KEY (id)
|
||||
);
|
@ -1,9 +0,0 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<title>Getting Started: Serving Web Content</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
</head>
|
||||
<body>
|
||||
<p>Hello from Docker!</p>
|
||||
</body>
|
Loading…
Reference in New Issue