diff --git a/pom.xml b/pom.xml
index f34c1936df..e88b545b7c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -54,14 +54,14 @@
-
-
-
- org.springframework.boot
- spring-boot-maven-plugin
-
-
-
+
+
+
+
+
+
+
+
diff --git a/src/main/java/guru/springframework/spring5webapp/bootstrap/BootStrapData.java b/src/main/java/guru/springframework/spring5webapp/bootstrap/BootStrapData.java
new file mode 100644
index 0000000000..5e1dc4835b
--- /dev/null
+++ b/src/main/java/guru/springframework/spring5webapp/bootstrap/BootStrapData.java
@@ -0,0 +1,44 @@
+package guru.springframework.spring5webapp.bootstrap;
+
+import guru.springframework.spring5webapp.domain.Author;
+import guru.springframework.spring5webapp.domain.Book;
+import guru.springframework.spring5webapp.repositories.AuthorRepository;
+import guru.springframework.spring5webapp.repositories.BookRepository;
+import org.springframework.boot.CommandLineRunner;
+import org.springframework.stereotype.Component;
+
+@Component
+public class BootStrapData implements CommandLineRunner {
+
+ private final AuthorRepository authorRepository;
+ private final BookRepository bookRepository;
+
+ public BootStrapData(AuthorRepository authorRepository, BookRepository bookRepository) {
+ this.authorRepository = authorRepository;
+ this.bookRepository = bookRepository;
+ }
+
+ @Override
+ public void run(String... args) throws Exception {
+
+ Author eric = new Author("Eric", "Evans");
+ Book ddd = new Book("Domain Driven Design","123123");
+ eric.getBooks().add(ddd);
+ ddd.getAuthors().add(eric);
+
+ authorRepository.save(eric);
+ bookRepository.save(ddd);
+
+ Author rod = new Author("Rod", "Johnson");
+ Book noEJB = new Book("J2EE Development without EJB", "872362");
+ rod.getBooks().add(noEJB);
+ noEJB.getAuthors().add(rod);
+
+ System.out.println("Started in bootStrap");
+ System.out.println("Number of books: " + bookRepository.count());
+
+ authorRepository.save(rod);
+ bookRepository.save(noEJB);
+
+ }
+}
diff --git a/src/main/java/guru/springframework/spring5webapp/domain/Author.java b/src/main/java/guru/springframework/spring5webapp/domain/Author.java
new file mode 100644
index 0000000000..41eb9805f5
--- /dev/null
+++ b/src/main/java/guru/springframework/spring5webapp/domain/Author.java
@@ -0,0 +1,83 @@
+package guru.springframework.spring5webapp.domain;
+
+import javax.persistence.*;
+import java.util.HashSet;
+import java.util.Set;
+
+@Entity
+public class Author {
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.AUTO)
+ private Long id;
+ private String firstName;
+ private String lastName;
+
+ @ManyToMany(mappedBy = "authors")
+ private Set books = new HashSet<>();
+
+ public Author() {
+ }
+
+ public Author(String firstName, String lastName) {
+ this.firstName = firstName;
+ this.lastName = lastName;
+ }
+
+ 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;
+ }
+
+ public Set getBooks() {
+ return books;
+ }
+
+ public void setBooks(Set books) {
+ this.books = books;
+ }
+
+ @Override
+ public String toString() {
+ return "Author{" +
+ "id=" + id +
+ ", firstName='" + firstName + '\'' +
+ ", lastName='" + lastName + '\'' +
+ ", books=" + books +
+ '}';
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ Author author = (Author) o;
+
+ return id != null ? id.equals(author.id) : author.id == null;
+ }
+
+ @Override
+ public int hashCode() {
+ return id != null ? id.hashCode() : 0;
+ }
+}
diff --git a/src/main/java/guru/springframework/spring5webapp/domain/Book.java b/src/main/java/guru/springframework/spring5webapp/domain/Book.java
new file mode 100644
index 0000000000..24adeafc67
--- /dev/null
+++ b/src/main/java/guru/springframework/spring5webapp/domain/Book.java
@@ -0,0 +1,77 @@
+package guru.springframework.spring5webapp.domain;
+
+import javax.persistence.*;
+import java.util.HashSet;
+import java.util.Set;
+
+@Entity
+public class Book {
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.AUTO)
+ private Long id;
+ private String title;
+ private String isBn;
+
+ @ManyToMany
+ @JoinTable(name="author_book", joinColumns = @JoinColumn(name = "book_id"),
+ inverseJoinColumns = @JoinColumn(name = "author_id"))
+ private Set authors = new HashSet<>();
+
+ public Book() {
+ }
+
+ public Book(String title, String isBn) {
+ this.title = title;
+ this.isBn = isBn;
+ }
+
+ public String getTitle() {
+ return title;
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ public String getIsBn() {
+ return isBn;
+ }
+
+ public void setIsBn(String isBn) {
+ this.isBn = isBn;
+ }
+
+ public Set getAuthors() {
+ return authors;
+ }
+
+ public void setAuthors(Set authors) {
+ this.authors = authors;
+ }
+
+ @Override
+ public String toString() {
+ return "Book{" +
+ "id=" + id +
+ ", title='" + title + '\'' +
+ ", isBn='" + isBn + '\'' +
+ ", authors=" + authors +
+ '}';
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ Book book = (Book) o;
+
+ return id != null ? id.equals(book.id) : book.id == null;
+ }
+
+ @Override
+ public int hashCode() {
+ return id != null ? id.hashCode() : 0;
+ }
+}
diff --git a/src/main/java/guru/springframework/spring5webapp/repositories/AuthorRepository.java b/src/main/java/guru/springframework/spring5webapp/repositories/AuthorRepository.java
new file mode 100644
index 0000000000..0e4f90ab47
--- /dev/null
+++ b/src/main/java/guru/springframework/spring5webapp/repositories/AuthorRepository.java
@@ -0,0 +1,7 @@
+package guru.springframework.spring5webapp.repositories;
+
+import guru.springframework.spring5webapp.domain.Author;
+import org.springframework.data.repository.CrudRepository;
+
+public interface AuthorRepository extends CrudRepository {
+}
diff --git a/src/main/java/guru/springframework/spring5webapp/repositories/BookRepository.java b/src/main/java/guru/springframework/spring5webapp/repositories/BookRepository.java
new file mode 100644
index 0000000000..570726803e
--- /dev/null
+++ b/src/main/java/guru/springframework/spring5webapp/repositories/BookRepository.java
@@ -0,0 +1,7 @@
+package guru.springframework.spring5webapp.repositories;
+
+import guru.springframework.spring5webapp.domain.Book;
+import org.springframework.data.repository.CrudRepository;
+
+public interface BookRepository extends CrudRepository {
+}