JAVA-12420 Renamed docker to docker-modules
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
FROM adoptopenjdk:11-jre-hotspot
|
||||
MAINTAINER baeldung.com
|
||||
|
||||
ARG JAR_FILE=*.jar
|
||||
COPY ${JAR_FILE} application.jar
|
||||
|
||||
ENTRYPOINT ["java", "-jar", "application.jar"]
|
||||
@@ -0,0 +1,22 @@
|
||||
version: '2'
|
||||
|
||||
services:
|
||||
app:
|
||||
image: 'docker-spring-boot-postgres:latest'
|
||||
build:
|
||||
context: .
|
||||
container_name: app
|
||||
depends_on:
|
||||
- db
|
||||
environment:
|
||||
- SPRING_DATASOURCE_URL=jdbc:postgresql://db:5432/compose-postgres
|
||||
- SPRING_DATASOURCE_USERNAME=compose-postgres
|
||||
- SPRING_DATASOURCE_PASSWORD=compose-postgres
|
||||
- SPRING_JPA_HIBERNATE_DDL_AUTO=update
|
||||
|
||||
db:
|
||||
image: 'postgres:13.1-alpine'
|
||||
container_name: db
|
||||
environment:
|
||||
- POSTGRES_USER=compose-postgres
|
||||
- POSTGRES_PASSWORD=compose-postgres
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.baeldung.docker;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name = "customer")
|
||||
public class Customer {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private long id;
|
||||
|
||||
|
||||
@Column(name = "first_name", nullable = false)
|
||||
private String firstName;
|
||||
|
||||
@Column(name = "last_name", nullable = false)
|
||||
private String lastName;
|
||||
|
||||
public Customer() {
|
||||
super();
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
}
|
||||
|
||||
public void setFirstName(String firstName) {
|
||||
this.firstName = firstName;
|
||||
}
|
||||
|
||||
public String getLastName() {
|
||||
return lastName;
|
||||
}
|
||||
|
||||
public void setLastName(String lastName) {
|
||||
this.lastName = lastName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Customer [id=" + id + ", firstName=" + firstName + ", lastName=" + lastName + "]";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.baeldung.docker;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface CustomerRepository extends JpaRepository<Customer, Long> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.baeldung.docker;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
||||
import org.springframework.context.event.EventListener;
|
||||
|
||||
@SpringBootApplication
|
||||
public class DemoApplication {
|
||||
private final Logger logger = LoggerFactory.getLogger(DemoApplication.class);
|
||||
|
||||
@Autowired private CustomerRepository repository;
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(DemoApplication.class, args);
|
||||
}
|
||||
|
||||
@EventListener(ApplicationReadyEvent.class)
|
||||
public void runAfterStartup() {
|
||||
queryAllCustomers();
|
||||
createCustomer();
|
||||
queryAllCustomers();
|
||||
}
|
||||
|
||||
private void createCustomer() {
|
||||
Customer newCustomer = new Customer();
|
||||
newCustomer.setFirstName("John");
|
||||
newCustomer.setLastName("Doe");
|
||||
logger.info("Saving new customer...");
|
||||
this.repository.save(newCustomer);
|
||||
}
|
||||
|
||||
private void queryAllCustomers() {
|
||||
List<Customer> allCustomers = this.repository.findAll();
|
||||
logger.info("Number of customers: " + allCustomers.size());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.baeldung.docker;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
class DemoApplicationTests {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user