-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8b043ff
commit 7a3cd39
Showing
3 changed files
with
49 additions
and
6 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
src/main/java/guru/springframework/spring5webapp/bootstrap/BootStrapData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
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", "4423241241"); | ||
rod.getBooks().add(noEJB); | ||
noEJB.getAuthors().add(rod); | ||
|
||
authorRepository.save(rod); | ||
bookRepository.save(noEJB); | ||
|
||
System.out.println("Started in Bootstrap"); | ||
System.out.println("Number of Books: " + bookRepository.count()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters