-
Notifications
You must be signed in to change notification settings - Fork 535
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upgraded to Boot 2.2.1, this fixed the javax.net.ssl.SSLException thr…
…own when application was stopped because the mysql driver had a bug. Also added graceful stopping of the application. And a CommandLineRunner to control application from command line and avoid duplicated declaration of beans. Added dropping tables when app is closed, so it can be run as many times as necessary.
- Loading branch information
Showing
12 changed files
with
61 additions
and
58 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -6,3 +6,6 @@ build.xml | |
manifest.mf | ||
nbactions.xml | ||
nb-configuration.xml | ||
out/ | ||
*.iml | ||
.idea |
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
35 changes: 15 additions & 20 deletions
35
HibernateSpringBootAudit/src/main/java/com/bookstore/MainApplication.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 |
---|---|---|
@@ -1,47 +1,42 @@ | ||
package com.bookstore; | ||
|
||
import com.bookstore.auditor.AuditorAwareImpl; | ||
import com.bookstore.service.BookstoreService; | ||
import org.springframework.boot.ApplicationRunner; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.boot.CommandLineRunner; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.data.domain.AuditorAware; | ||
import org.springframework.data.jpa.repository.config.EnableJpaAuditing; | ||
|
||
@SpringBootApplication | ||
@EnableJpaAuditing(auditorAwareRef = "auditorAware") | ||
public class MainApplication { | ||
|
||
private final BookstoreService bookstoreService; | ||
|
||
public MainApplication(BookstoreService bookstoreService) { | ||
this.bookstoreService = bookstoreService; | ||
} | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(MainApplication.class, args); | ||
} | ||
private static final Logger logger = LoggerFactory.getLogger(MainApplication.class); | ||
|
||
@Bean | ||
public AuditorAware<String> auditorAware() { | ||
return new AuditorAwareImpl(); | ||
public static void main(String... args) throws Exception { | ||
var ctx = SpringApplication.run(MainApplication.class, args); | ||
|
||
logger.info("Started ..."); | ||
System.in.read(); | ||
ctx.close(); | ||
} | ||
|
||
@Bean | ||
public ApplicationRunner init() { | ||
public CommandLineRunner scheduleRunner(BookstoreService bookstoreService) { | ||
return args -> { | ||
System.out.println("Register new author ..."); | ||
bookstoreService.registerAuthor(); | ||
|
||
Thread.sleep(5000); | ||
|
||
System.out.println("Update an author ..."); | ||
bookstoreService.updateAuthor(); | ||
bookstoreService.updateAuthor(); | ||
|
||
Thread.sleep(5000); | ||
System.out.println("Update books of an author ..."); | ||
bookstoreService.updateBooks(); | ||
bookstoreService.updateBooks(); | ||
}; | ||
} | ||
} |
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
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
3 changes: 1 addition & 2 deletions
3
HibernateSpringBootAudit/src/main/java/com/bookstore/entity/Book.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
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
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
12 changes: 0 additions & 12 deletions
12
HibernateSpringBootAudit/src/main/resources/application.properties
This file was deleted.
Oops, something went wrong.
23 changes: 23 additions & 0 deletions
23
HibernateSpringBootAudit/src/main/resources/application.yml
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,23 @@ | ||
spring: | ||
datasource: | ||
url: jdbc:mysql://localhost:3306/bookstoredb?createDatabaseIfNotExist=true&useLegacyDatetimeCode=false | ||
username: root | ||
password: root | ||
|
||
jpa: | ||
hibernate.ddl-auto: create-drop | ||
show-sql: true | ||
properties: | ||
hibernate: | ||
dialect: org.hibernate.dialect.MySQL5Dialect | ||
jdbc: | ||
time_zone: UTC | ||
open-in-view: false | ||
|
||
logging: | ||
pattern: | ||
console: "%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n" | ||
level: | ||
root: INFO | ||
org.springframework: DEBUG | ||
com.apress.cems.reactive: DEBUG |