Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgraded to Boot 2.2.1, this fixed the javax.net.ssl.SSLException thr… #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ build.xml
manifest.mf
nbactions.xml
nb-configuration.xml
out/
*.iml
.idea
8 changes: 2 additions & 6 deletions HibernateSpringBootAudit/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.4.RELEASE</version>
<version>2.2.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<java.version>12</java.version>
<maven.compiler.source>12</maven.compiler.source>
<maven.compiler.target>12</maven.compiler.target>
</properties>
Expand All @@ -31,10 +31,6 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
Expand Down
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();
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
import java.util.Optional;
import java.util.Random;
import org.springframework.data.domain.AuditorAware;
import org.springframework.stereotype.Component;

@Component("auditorAware")
public class AuditorAwareImpl implements AuditorAware<String> {

@Override
public Optional<String> getCurrentAuditor() {
// use Spring Security to retrive the currently logged-in user(s)
return Optional.of(Arrays.asList("mark1990", "adrianm", "dan555")
.get(new Random().nextInt(3)));
// use Spring Security to retrieve the currently logged-in user(s)
return Optional.of(Arrays.asList("mark1990", "adrianm", "dan555").get(new Random().nextInt(3)));
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.bookstore.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
Expand All @@ -9,7 +8,7 @@
import javax.persistence.OneToMany;

@Entity
public class Author extends BaseEntity<String> implements Serializable {
public class Author extends BaseEntity<String> {

private static final long serialVersionUID = 1L;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.bookstore.entity;

import java.io.Serializable;
import java.time.LocalDateTime;
import javax.persistence.EntityListeners;
import javax.persistence.GeneratedValue;
Expand All @@ -14,7 +15,7 @@

@MappedSuperclass
@EntityListeners({AuditingEntityListener.class})
public abstract class BaseEntity<U> {
public abstract class BaseEntity<U> implements Serializable {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package com.bookstore.entity;

import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;

@Entity
public class Book extends BaseEntity<String> implements Serializable {
public class Book extends BaseEntity<String> {

private static final long serialVersionUID = 1L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
@Repository
public interface AuthorRepository extends JpaRepository<Author, Long> {

public Author findByName(String name);
Author findByName(String name);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,25 @@ public BookstoreService(AuthorRepository authorRepository) {
@Transactional
public void registerAuthor() {

Author a1 = new Author();
var a1 = new Author();
a1.setName("Quartis Young");
a1.setGenre("Anthology");
a1.setAge(34);

Author a2 = new Author();
var a2 = new Author();
a2.setName("Mark Janel");
a2.setGenre("Anthology");
a2.setAge(23);

Book b1 = new Book();
var b1 = new Book();
b1.setIsbn("001");
b1.setTitle("The Beatles Anthology");

Book b2 = new Book();
var b2 = new Book();
b2.setIsbn("002");
b2.setTitle("A People's Anthology");

Book b3 = new Book();
var b3 = new Book();
b3.setIsbn("003");
b3.setTitle("Anthology Myths");

Expand All @@ -52,14 +52,13 @@ public void registerAuthor() {

@Transactional
public void updateAuthor() {
Author author = authorRepository.findByName("Mark Janel");

var author = authorRepository.findByName("Mark Janel");
author.setAge(45);
}

@Transactional
public void updateBooks() {
Author author = authorRepository.findByName("Quartis Young");
var author = authorRepository.findByName("Quartis Young");
List<Book> books = author.getBooks();

for (Book book : books) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
public class UserService {

public String getCurrentUserName() {
// use Spring Security to retrive the current user
return Arrays.asList("mark1990", "adrianm", "dan555")
.get(new Random().nextInt(3));
// use Spring Security to retrieve the current user
return Arrays.asList("mark1990", "adrianm", "dan555").get(new Random().nextInt(3));
}
}
12 changes: 0 additions & 12 deletions HibernateSpringBootAudit/src/main/resources/application.properties

This file was deleted.

23 changes: 23 additions & 0 deletions HibernateSpringBootAudit/src/main/resources/application.yml
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