Lab#SB09-1: SpringIO Conference
Spring IO Conference Barcelona
📘 Spring Boot Lab#SB09-1: SpringIO Conference
This lab explores all the topics from the UML diagram
for the entities Conference
, Book
, and Speaker
; example objects; Java entity code; object creation; and SQL data initialization.
Besides, we will create the Spring Boot Vaadin
project and push to remote repo.
1 UML Class Diagram
For Conference
, Book
, and Speaker
1.1 Fake Data Objects
- Spring.io Barcelona 2024
- Conference: “Spring Boot Updates”, Date: 2024-05-15, Room: “Auditorium A”, Duration: 90 minutes, Link: “youtube.com/2024springboot”
- Book: “Spring in Action”, Author: “Craig Walls”, ISBN: “9781617294945”
- Speaker: “John Doe”, Bio: “Senior Developer Advocate”, Email: “john.doe@example.com”
- Spring.io Barcelona 2023
- Conference: “Reactive Programming with Spring”, Date: 2023-04-20, Room: “Room B”, Duration: 75 minutes, Link: “youtube.com/2023reactive”
- Book: “Reactive Spring”, Author: “Josh Long”, ISBN: “9781617297571”
- Speaker: “Jane Smith”, Bio: “Spring Developer”, Email: “jane.smith@example.com”
- Spring.io Barcelona 2022
- Conference: “Kubernetes and Spring Cloud”, Date: 2022-03-10, Room: “Main Hall”, Duration: 60 minutes, Link: “youtube.com/2022kubernetes”
- Book: “Cloud Native Java”, Author: “Josh Long & Kenny Bastani”, ISBN: “9781449374648”
- Speaker: “Alice Johnson”, Bio: “Cloud Architect”, Email: “alice.johnson@example.com”
1.2 Java Entities
We are creating @Entity
objects with:
- the
builder
pattern - the
UUID
generator - and
Lombok
1.2.1 @Builder
The @Builder
annotation is part of Project Lombok
, a Java library
that automatically generates boilerplate code through annotations. It’s a convenient way to implement the Builder
pattern without manually writing all the builder code.
The technique in Java for writing long expressions using the dot operator
is known as the Builder Pattern.
This pattern is a creational design pattern that allows for the step-by-step construction of complex objects.
It is particularly useful when an object requires many configuration options, enabling method chaining to make the code more readable and maintainable.
1.2.2 Conference SpringIO
Entities
Conference Entity
import lombok.*;
import org.hibernate.annotations.GenericGenerator;
import javax.persistence.*;
import java.util.UUID;
@Entity
@Table(name = "conferences")
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class Conference {
@Id
@GeneratedValue(generator = "UUID")
@GenericGenerator(name = "UUID",
strategy = "org.hibernate.id.UUIDGenerator")
@Column(name = "id", updatable = false,
nullable = false)
private UUID id;
@Column(nullable = false)
private String date;
@Column(name = "youtube_link")
private String linkToYouTubeVideo;
@Column(nullable = false)
private String title;
@Column(name = "conference_name",
nullable = false)
private String conferenceName;
@Column(columnDefinition = "TEXT")
private String content;
private Integer duration;
private String room;
@ManyToOne
@JoinColumn(name = "book_id",
nullable = false)
private Book book;
@ManyToOne
@JoinColumn(name = "speaker_id",
nullable = false)
private Speaker speaker;
}
Book Entity
import lombok.*;
import org.hibernate.annotations.GenericGenerator;
import javax.persistence.*;
import java.util.List;
import java.util.UUID;
@Entity
@Table(name = "books")
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class Book {
@Id
@GeneratedValue(generator = "UUID")
@GenericGenerator(name = "UUID",
strategy = "org.hibernate.id.UUIDGenerator")
@Column(name = "id", updatable = false,
nullable = false)
private UUID id;
@Column(nullable = false)
private String title;
@Column(nullable = false)
private String author;
@Column(nullable = false, unique = true)
private String ISBN;
@OneToMany(mappedBy = "book")
private List<Conference> conferences;
}
Speaker Entity
import lombok.*;
import org.hibernate.annotations.GenericGenerator;
import javax.persistence.*;
import java.util.List;
import java.util.UUID;
@Entity
@Table(name = "speakers")
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class Speaker {
@Id
@GeneratedValue(generator = "UUID")
@GenericGenerator(name = "UUID",
strategy = "org.hibernate.id.UUIDGenerator")
@Column(name = "id", updatable = false,
nullable = false)
private UUID id;
@Column(nullable = false)
private String name;
@Column(columnDefinition = "TEXT")
private String bio;
@Column(nullable = false, unique = true)
private String email;
@OneToMany(mappedBy = "speaker")
private List<Conference> conferences;
}
1.3 Creating Conference
Objects
We’ll instantiate the Conference
, Book
, and Speaker
classes. Here’s how we can do this using the builder
pattern provided by Lombok:
@Entity
creation
Object 1
Book book1 = Book.builder()
.id(UUID.randomUUID())
.title("Spring Boot in Action")
.author("Craig Walls")
.ISBN("9781617292545")
.build();
Speaker speaker1 = Speaker.builder()
.id(UUID.randomUUID())
.name("Stéphane Nicoll")
.bio("Spring Framework committer")
.email("snicoll@pivotal.io")
.build();
Conference conference1 = Conference.builder()
.id(UUID.randomUUID())
.date("2023-05-17")
.linkToYouTubeVideo("https://www.youtube.com/watch?v=TtQTF7M9xPo")
.title("Spring Boot 3.0 & Spring Framework 6.0: What's New")
.conferenceName("Spring I/O 2023")
.content("Overview of new features in Spring Boot 3.0 and Spring Framework 6.0, including Java 17 baseline, native compilation, and observability improvements.")
.duration(50)
.room("Auditorium 1")
.book(book1)
.speaker(speaker1)
.build();
Object 2
Book book2 = Book.builder()
.id(UUID.randomUUID())
.title("Spring Security in Action")
.author("Laurentiu Spilca")
.ISBN("9781617297731")
.build();
Speaker speaker2 = Speaker.builder()
.id(UUID.randomUUID())
.name("Rob Winch")
.bio("Spring Security lead")
.email("rwinch@pivotal.io")
.build();
Conference conference2 = Conference.builder()
.id(UUID.randomUUID())
.date("2023-05-18")
.linkToYouTubeVideo("https://www.youtube.com/watch?v=wYYKNhCXVVE")
.title("Securing Spring Boot 3 Applications")
.conferenceName("Spring I/O 2023")
.content("Exploration of security features in Spring Boot 3, including OAuth 2.0 and OpenID Connect support, and best practices for securing microservices.")
.duration(45)
.room("Room B")
.book(book2)
.speaker(speaker2)
.build();
Object 3
Book book3 = Book.builder()
.id(UUID.randomUUID())
.title("Reactive Spring")
.author("Josh Long")
.ISBN("9781732910225")
.build();
Speaker speaker3 = Speaker.builder()
.id(UUID.randomUUID())
.name("Josh Long")
.bio("Spring Developer Advocate")
.email("jlong@pivotal.io")
.build();
Conference conference3 = Conference.builder()
.id(UUID.randomUUID())
.date("2022-05-26")
.linkToYouTubeVideo("https://www.youtube.com/watch?v=TKK4Oi1Xc-Y")
.title("Reactive Spring")
.conferenceName("Spring I/O 2022")
.content("Deep dive into reactive programming with Spring, covering Project Reactor, Spring WebFlux, and reactive data access.")
.duration(55)
.room("Main Hall")
.book(book3)
.speaker(speaker3)
.build();
Object 4
Book book4 = Book.builder()
.id(UUID.randomUUID())
.title("Native Image Definitive Guide")
.author("Oleg Šelajev")
.ISBN("9781492078531")
.build();
Speaker speaker4 = Speaker.builder()
.id(UUID.randomUUID())
.name("Sébastien Deleuze")
.bio("Spring Framework committer")
.email("sdeleuze@vmware.com")
.build();
Conference conference4 = Conference.builder()
.id(UUID.randomUUID())
.date("2024-05-23")
.linkToYouTubeVideo("https://www.youtube.com/placeholder_2024")
// Placeholder link for future conference video.
.
title="Spring Native and GraalVM: The Future of Spring Applications"
conferenceName="Spring I/O 2024"
content="Exploring the latest advancements in Spring Native and GraalVM integration, focusing on performance improvements and reduced startup times."
duration=60
room="Innovation Theater"
book=book4
speaker=speaker4
build();
1.4 SQL Data Initialization with data.sql
Create a data.sql
file in src/main/resources
with the following content:
-- Insert Books
INSERT INTO books (id, title, author, isbn) VALUES
(UUID(), 'Spring Boot in Action', 'Craig Walls', '9781617292545'),
(UUID(), 'Spring Security in Action', 'Laurentiu Spilca', '9781617297731'),
(UUID(), 'Reactive Spring', 'Josh Long', '9781732910225'),
(UUID(), 'Native Image Definitive Guide', 'Oleg Šelajev', '9781492078531');
-- Insert Speakers
INSERT INTO speakers (id, name, bio, email) VALUES
(UUID(), 'Stéphane Nicoll', 'Spring Framework committer', 'snicoll@pivotal.io'),
(UUID(), 'Rob Winch', 'Spring Security lead', 'rwinch@pivotal.io'),
(UUID(), 'Josh Long', 'Spring Developer Advocate', 'jlong@pivotal.io'),
(UUID(), 'Sébastien Deleuze', 'Spring Framework committer', 'sdeleuze@vmware.com');
-- Insert Conferences
INSERT INTO conferences (id, date, link_to_youtube_video, title, conference_name, content, duration, room, book_id, speaker_id) VALUES
(UUID(), '2023-05-17', 'https://www.youtube.com/watch?v=TtQTF7M9xPo', 'Spring Boot 3.0 & Spring Framework 6.0: What''s New', 'Spring I/O 2023', 'Overview of new features in Spring Boot 3.0 and Spring Framework 6.0.', 50, 'Auditorium 1', (SELECT id FROM books WHERE title='Spring Boot in Action'), (SELECT id FROM speakers WHERE name='Stéphane Nicoll')),
(UUID(), '2023-05-18', 'https://www.youtube.com/watch?v=wYYKNhCXVVE', 'Securing Spring Boot 3 Applications', 'Spring I/O 2023', 'Exploration of security features in Spring Boot.', 45, 'Room B', (SELECT id FROM books WHERE title='Spring Security in Action'), (SELECT id FROM speakers WHERE name='Rob Winch')),
(UUID(), '2022-05-26', 'https://www.youtube.com/watch?v=TKK4Oi1Xc-Y', 'Reactive Spring', 'Spring I/O 2022', 'Deep dive into reactive programming with Spring.', 55, 'Main Hall', (SELECT id FROM books WHERE title='Reactive Spring'), (SELECT id FROM speakers WHERE name='Josh Long')),
(UUID(), '2024-05-23', 'https://www.youtube.com/placeholder_2024', 'Spring Native and GraalVM: The Future of Spring Applications', 'Spring I/O 2024', 'Exploring advancements in Spring Native.', 60, 'Innovation Theater', (SELECT id FROM books WHERE title='Native Image Definitive Guide'), (SELECT id FROM speakers WHERE name='Sébastien Deleuze'));
1.4.1 UUID
The UUID()
function in the SQL statements
is a placeholder for generating unique identifiers for each record. In a real-world scenario, UUIDs (Universally Unique Identifiers)
are typically generated by the application layer rather than directly in SQL, especially when using JPA with Hibernate
in a Spring Boot application.
When using JPA with Hibernate, UUIDs can be automatically generated by annotating the entity’s ID field with @GeneratedValue
and specifying a UUID
generator strategy.
To generate UUIDs directly in a SQL script for different databases, you can use specific functions provided by each database system. Here are examples for some popular databases:
MySQL
-- MySQL uses the UUID() function to generate a UUID.
INSERT INTO books (id, title, author, isbn) VALUES
(UUID(), 'Spring Boot in Action', 'Craig Walls', '9781617292545');
PostgreSQL
-- PostgreSQL requires the uuid-ossp extension for generating UUIDs.
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
INSERT INTO books (id, title, author, isbn) VALUES
(uuid_generate_v4(), 'Spring Boot in Action', 'Craig Walls', '9781617292545');
SQL Server
-- SQL Server uses the NEWID() function to generate a UUID.
INSERT INTO books (id, title, author, isbn) VALUES
(NEWID(), 'Spring Boot in Action', 'Craig Walls', '9781617292545');
H2 Database
2 Create Project
Reference code:
Spring Init zip project.
2.1 Project structure
2.2 View
The output we see when running a new Spring Boot Vaadin project
hasn’t been configured with any views yet.
Spring Boot
with Vaadin
is a framework for building web applications using Java
. When you start a new project, it creates a basic structure but doesn’t include any views by default. Views in Vaadin
are components
that represent different pages or sections of your application’s user interface.
The message “No views found” indicates that the application is running, but there are no defined views to display. This is expected in a fresh project.
The output then provides two main options for creating views:
- Using
Flow
: This allows you to code the UI in Java, which is Vaadin’s traditional approach. - Using
Hilla
andReact
: This is a newer option that lets you code the UI inTypeScript
withReact
components.
This output is essentially a starting point, prompting you to begin building your application’s user interface by creating views using either of the suggested methods or by following the tutorial for more detailed guidance.