Log In
Or create an account ->
Imperial Library
Home
About
News
Upload
Forum
Help
Login/SignUp
Index
Title Page
Copyright and Credits
Spring Boot 2 Fundamentals
Packt Upsell
Why Subscribe?
Packt.com
Contributors
About the Authors
Packt Is Searching for Authors Like You
Preface
Who This Book Is For
What This Book Covers
To Get the Most out of This Book
Download the Example Code Files
Conventions Used
Get in Touch
Reviews
The Spring Project and Framework
Introduction to the Spring Framework
A Short History
Spring Key Principles
J2EE Pain Points
Spring as a Counterpart for J2EE
Inversion of Control and Dependency Injection
Inversion of Control and Dependency Injection Overview
The Spring Framework
The Spring Ecosystem
Spring Boot Features
Bootstrapping
Spring Initializr
Creating the First Spring Initializr Project
Examining the Project in the IDE
Running a Project with Different Options
The Application Context
Spring Bean
Spring Bean Stereotypes
Exploring Spring Beans
Configuration Classes
Classpath Scanning
Additional Tools – Project Lombok
Java Beans
Java Class
Example Class
Project Lombok to the Rescue
Project Lombok Enhanced Class
Activity: Project Lombok in Action
Summary
Building a Spring Application
Dependency Injection in Spring
Autowiring
Injection Types
Field Injection
Property Injection
Config Method Injection
Constructor Injection
Circular Dependencies
Qualify Beans
Bean Scopes
Configuration Classes
Utilizing Bean Interdependencies
Configuration of Spring Boot Applications
Profiles
Conditional Beans
Utilizing Conditional Beans for Various Implementations
Spring Configuration Files
Property Files
YAML Files
Multi-Profile YAML Files
External Configuration Locations
Placeholders in Configuration Files
Accessing Environment Values
Annotated Fields
Spring Expression Language
Configuration Property Classes
Activity: Examining Autowiring and Configurations
Summary
Testing Spring Applications
Applying Unit Tests
Unit Testing
Test Types – Side by Side
Writing Unit Tests with Plain JUnits
Writing Unit Tests with Mockito Support
Creating Unit Tests
Integration Tests
The @SpringBootTest Annotation
Testing Beans
Configuring the Test Context
Activity: Writing Integration Tests
Summary
The MVC Pattern
Introducing the MVC Pattern
The MVC Components
Comparing Model, View, and Controller
Interacting
Advantages and Disadvantages of the MVC Pattern
Request-Based versus Component-Based MVC
Spring Web MVC Basics
Single-Page Applications Versus Multi-Page Applications
SPA versus MPA
Java Servlet API
Servlet API Components
Spring Web MVC
Utilizing Spring Web MVC Starter
The Embedded Web Server
Spring DispatcherServlet
DispatcherServlet Interaction
Controller as Components
Static Views with HTML and Assets
Adding Client-Side Web Libraries Through WebJars
Styling with Bootstrap
Transforming the Template Engine
Thymeleaf Snippet
Passing Data Along with Models
Spring Web MVC Controller
The @RequestMapping Annotation
Additional Annotations and Parameters for Handler Methods
@RequestParam
@RequestHeader
@CookieValue
@PathVariable
@ModelAttribute
@RequestBody
@ResponseBody
Additional Content – Properties to Configure Web MVC
Filter
Configuring Spring Web MVC
Activity: Creating Your First Web MVC Controller
Summary
Displaying Information Using Web Pages
HTML Templating with Thymeleaf
Templating Engine
Integrating Thymeleaf Into a Spring Boot Application
A Basic Thymeleaf Template
Externalizing Text
Create Context Aware URLs
Statements in Thymeleaf Templates
Bootstrapping and Templating With Thymeleaf
Displaying Data Using a Model and Data Binding
How Spring Web MVC Handles the Model
Model-View Interaction
Passing the Model as a Parameter to a Handler Method
Returning Model Attributes from a Controller Method
Using @ModelAttribute to Initialize Model Attributes
How a View is Selected by the Spring Framework
Selecting a View Template by Returning Its Name
Redirecting to a URL Instead of Rendering a View Directly
Selecting a View and Returning a Model at the Same Time
Working with the Model in Thymeleaf Templates
Binding Model Data to a Thymeleaf Template
Adding Dynamic Data
Iterating and Displaying Items from a List
Handling Lists
Displaying Parts of the View Using Conditions
Displaying Text Conditionally
Activity: Displaying the Details of a Blog Post
Summary
Passing Data Between the View and the Controller
Form Handling
HTML Forms
Post Data Handling
Creating a Form Template
Simple Input Field
Implementing Thymeleaf Form Syntax
Form-Backing Beans
Populating a Form Bean for Editing
Starting with Form Data Processing
Bean Validation
Adding Validation Messages to Templates
Utilizing Spring's Validation Facilities
Customizing Validation Messages
Setting a New Default Message for a Validator
Setting the Message for a Bean Property
Providing Translation for Messages
Modifying Validation Messages
Form Input Types and Value Binding
Inputting Elements for Text or Number (text, hidden, password)
Inputting Elements for Selections (Checkbox, Radio)
Input Elements for User Interaction (submit)
Select (single, multi-select)
Selecting Multiple Values
Textarea (Regular, Unsafe Content)
Safe/Unsafe Text
Utilizing Checkboxes in Thymeleaf
Activity: Creating a Page to Enter a New Blog Post Category
Summary
RESTful APIs
What is a RESTful API?
REST – Formal Definition
The RESTful API – Practitioner's Definition
Showing the Yes/No API in Postman
REST Guiding Principles
REST Resource Examples
Utilizing SWAPI
REST Controllers in Spring
What makes a REST Controller Different?
"Response Body" in Detail
Returning JSON Manually
Manual JSON, Correct Content-Type
Mapping Data to JSON
REST Controllers in Spring
Implementing REST Endpoints 
Content Types
Producing Different Content Types
Responding with XML to the Rest-intro Application
Job Aid
Consuming Different Content Types
HTTP Status Code and Important Headers
Declarative Status Code
Programmatic Status Code
Global Error Handling
A JavaScript Evaluator
Advising Many Controllers at Once
Controlling Headers
Returning Different Status Codes
Hypermedia with Spring Boot
HATEOAS Introduction
Extending an Application with Spring HATEOAS
Creating a HATEOAS Resource
Activity: Creating a List of Blog Articles as a REST Resource
Summary
Web Application Security
Securing Your Web Application
Threats to Software Security
Interpreting Untrusted Data
Injection
Insecure Deserialization
Allowing Access from Foreign Clients
Allowing Access to Resources Not Owned
Insufficient Logging and Monitoring
Authentication and Authorization
Authentication
Authorization
Examining Baby-step Security (1)
Spring Security
The Magic of Auto-Configured Spring Security
Tight Spring Security Defaults
Securing REST with Basic Auth
Securing Web Browsing in the Session
Examining Baby-step Security (2)
Explicit Configuration
Security Configuration Entry Point
Adding Hardcoded Users
Locking Paths with Basic Auth
Adding a Login
Adding a Logout
Exploring Web Security
Method-Level Security
Roles Allowed
Enable @RolesAllowed
Securing Controllers
The Original @Secured Method
Expression-Based Security
Simple Expressions
Powerful Expressions
Beyond Access – Filtering
Testing Security Aspects
The Security Context
A Real User Repository
Password Encoders
Wiring it Together
Real Repositories
Cross-Site Request Forgery (CSRF)
Cross-Origin Resource Sharing (CORS)
Activity: Exploring Security Annotations
Summary
Persisting Data Using a Database
Relational Databases and SQL
Relational Database Management Systems (RDBMS)
The H2 Embedded Database
Utilizing the H2 Console
The Gist of SQL
DDL Table Creation
DML Data Manipulation
Accessing the Database from Java with JDBC and JdbcTemplate
Importing Initial Data
Plain JDBC
Plain JDBC Examples
Plain JDBC Since Java 7
JDBC Resources to Handle
Spring to the Rescue – JdbcTemplate
In detail: Creating the JdbcTemplate
Exception Translation
Advanced Queries
Other Result Types
Returning Multiple Values
Returning Structured Data
Mapping Rows
Mapping Rows (short)
Advanced Mapping: Row-Spanning
CRUD Operations
Schema Updates
Database Migrations with Flyway
Utilizing Flyway
Flyway – Behind the Scenes
Non-Trivial Migrations
Outlook – Advanced Database Support
External Databases
Connection Pooling
Other Database Technologies – JPA and Spring Data
Other Database Technologies – jOOQ
Activity: Creating an SMS Application to Display Multiple Authors
Summary
Book Summary
Solutions
Chapter 1: The Spring Project and Framework
Activity: Project Lombok in Action
Chapter 2: Building a Spring Application
Activity: Autowiring and Configurations
Chapter 3: Testing Spring Applications
Activity: Writing Integration Tests
Chapter 4: The MVC Pattern
Activity: Create Your First Web MVC Controller
Chapter 5: Displaying Information Using Web Pages
Activity: Displaying the Details of a Blog-Post
Chapter 6: Passing Data Between the View and the Controller
Activity: Creating a Page to Enter a New Blog Post
Chapter 7: RESTful APIs
Activity: Creating a List of Blog Articles as a REST Resource
Chapter 8: Web Application Security
Activity: Exploring Security Annotations
Chapter 9: Persisting Data Using a Database
Activity: Creating an SMS Application to Display Multiple Authors
Solutions Summary
Other Books You May Enjoy
Leave a Review - Let Other Readers Know What You Think
← Prev
Back
Next →
← Prev
Back
Next →