
In this introduction we are going to discuss what you can expect from this course. I will give you a brief intro to who I am and why I am so passionate about what I do.
In this lesson we are going to discuss what our goals are for the course. We will define who this course is for and more importantly who this course isn't for.
In this lesson we are going to make sure that we all have our development environment setup correctly. All the links for the resources we discuss in this lesson will be in the documentation. You haven't seen the docs yet but we will discuss this in an upcoming lesson.
Many students get confused about what the Spring Framework is used for vs why we need Spring Boot. In this lesson I will try and answer those questions.
The course resources update informs students about changed resource locations, including the new danveiga.dev blog and updated documentation, plus the spring docs and templates repositories on GitHub.
I have spent a lot of time writing documentation for this course and I really hope it pays off. I will include a link to the github repository in the additional resources. Every single thing we are going to talk about is in the documentation.
In this course we are going to build a clone of reddit. In this lesson we are going to talk about reddit and what we can expect to build in this course.
Create the initial Spring Boot project with Spring Initializr, selecting Java 9 (Java 8 also possible) and web dependencies, then observe dependency resolution and the H2 in-memory database for development.
Now that we have created our application, it's time to explore what the Spring Initializr actually did for us.
In this lesson we are going to look at the requirements for this project.
In this lesson we will discuss the process for creating the templates used in this project.
In this lesson we will take a look at a quick domain model that I have created. This will at least give us a plan to start creating our domain model in our application.
In this section we are going to look at where the repositories are for this course. We will also create the initial repository for this project and talk about our branching strategy.
In this lesson we are going to create the initial repository and pushing it to Github.
In this lesson we are going to talk about creating a README file for your Github project.
In this lesson we are going to discuss our branching strategy for this course. Each time that we begin to create a new feature we will create a new branch.
In the documentation I added some useful links to learn all about using Git & Github.
In this lesson we are going to discuss what we need to cover in this section.
Spring Boot DevTools
Configuration & Properties
Profiles
Debugging & Logging
Actuator
In this lesson we are going to talk about one of my favorite essentials, Spring Boot Developer Tools. The Developer Tools help make us a more productive developer and you really should be using them in your development environment.
Configure spring boot dev tools with application properties and configuration properties. Learn to generate configuration metadata, set defaults, and override them in application properties or yaml.
Profiles give us a nice clean approach to separate our configuration for different environments.
In this lesson we are going to discuss debugging & logging. I think these are 2 important skills that help me become a better developer.
In this lesson I am going to introduce you to the Spring Boot Actuator. We are also going to discuss what has changed from Spring Boot 1.x
In this lesson we are going to introduce Spring Data JPA. What is JPA, Hibernate and how does this all fit into our application?
In this lesson we are going to start building our model by creating some entities.
In this lesson we are going to refactor our entities using Project Lombok.
The central interface in the Spring Data repository abstraction is Repository. In this lesson we are going to create a repository for Link and Comment.
In this lesson we are going to discuss the relationships (Mappings) between our entities.
Spring Data provides sophisticated support to transparently keep track of who created or changed an entity and when the change happened. To benefit from that functionality, you have to equip your entity classes with auditing metadata that can be defined either using annotations or by implementing an interface.
We are going to merge our model branch back into master.
In the last section we took a look at how we build out our entities and repositories. We also learned that our entities map directly to a database table. The question that remains is where is this database located? Is it being created for us or is this up to us? We are going to answer these questions and more in this section.
Database Configuration
Common Database Properties
H2 vs MySQL
SQL Logging
Hibernate logging level DEBUG
Database Initialization
Hibernate DDL
schema.sql
data.sql
CommandLineRunner
If you can’t always remember what properties can be set in your application.properties there is a really good reference at the link below.
https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html
DATASOURCE (DataSourceAutoConfiguration & DataSourceProperties)
JPA (JpaBaseConfiguration, HibernateJpaAutoConfiguration)
H2 Web Console
In the previous lesson we looked at how to use the H2 in-memory database. That is great for getting started but at some point we will want to move to a production ready database like MySQL. If you are using some other DBMS just do a quick search for what your settings will look like.
A database can be initialized in different ways depending on what your stack is. Of course, you can also do it manually, provided the database is a separate process. In this lesson we are going to look at how we can initialize the database schema and data.
In this lesson we are going to look at a way to initialize our database using Java and the Command Line Runner interface.
In this lesson we are going to talk about how we can explore our repositories. We are also going to close out this section and merge the branch back into master.
We are now into the C in our MVC application. The C stands for controller and you can think of the controller as the traffic cop in our application. The controller handles incoming http requests and "directs traffic". Methods in your controller are mapped to HTTP by using @RequestingMapping (or one of its composed) annotations.
In this lesson we are going to discuss the differences between Controller and Rest Controller. We will also take some time to discuss what the @RequestMapping annotation is and what it can do for us.
@RequestMapping handler methods have a flexible signature and can choose from a range of supported controller method arguments and return values. I have included a link to the documentation that covers all of the available handler method arguments.
Now that we know a little bit more about controllers and what methods are available to us we should be able to start building out the basic parts of our Link Controller.
It is time to close out this section and clean up our branch. Finally we are going to merge our spring-mvc-controller branch into master.
If we were creating a REST service application we wouldn’t need any view. Instead we are creating a Spring MVC app with a front end using a template engine. As we will see in a bit, we have many choices when it comes to what template engines we can use.
Now that we know how to serve static content we need to understand how to serve dynamic content. This is where templates come into play and lucky for us Spring MVC supports a variety of template engines.
In this lesson we are going to discuss what is needed to get started with Thymeleaf.
I mentioned these towards the beginning of the course and it’s finally time to use them. If you missed it earlier I created these so we wouldn’t have to waste time designing some basic templates. The point of this course is to teach you all about Spring Boot, not design. If you haven’t already downloaded them please do so now.
In our templates, we will often want to include parts from other templates, parts like footers, headers, menus…
In order to do this, Thymeleaf needs us to define these parts, “fragments”, for inclusion, which can be done using the th:fragment attribute.
Now that we have our layout it’s time to build our first page, our list of links. Before we get started it would be a good idea to have a list of links in our database. I went over to one of my favorite subreddits /r/springboot and just grabbed 11 items for testing.
In this lesson we are going to build a link view page.
In this lesson we are going to build our submit link page.
In this lesson we are going to wrap up this section on Spring MVC: View. We are also going to merge this branch back into master.
In this lesson we are going to discuss a very important topic and that is security. It turns out that Security is really hard and it isn’t something that we want to build ourselves. Luckily for us the Spring Security project is the standard for securing Spring based applications and it is really good at it.
In this lesson we are going to learn how to configure Spring Security. This is the start of our configuration but this is going to be something we build on throughout the course.
In the last lesson we used the default user & auto generated password to test our configuration. While It was good for a quick test we really need to implement something a little bit better. In this lesson we are going to create our User & Role entities and hook them into Spring Security.
The User Details Service is a core interface in Spring Security. In this lesson we are going to look at how we can configure our user details service.
Now that we have everything in place we can add some data for us to use in our development environment. In this lesson we will add some users & roles test data.
Now that we have security in place and we have some users and roles it’s time we revisit something we did a little bit earlier. Remember when we created the Auditable domain class that all of our other domain classes extended? Well we have the created & last updated dates working but now its time we tackle the user fields.
Now that Spring Boot has backed off of Security we have a little bit of an issue with our actuator endpoints. Right now they are all wide open, so any user can get to them. In some cases this might be ok but in most it’s probably not. Let’s think about some rules that we want to incorporate for our actuator endpoints.
If we try and go to our H2 Console (/h2-console) we won’t be able to get there. We need to do a couple of things to make this work.
What we looked at in the last section was how to configure Spring Security. Now that we have a head start on security it’s time we integrate into our view layer. Here is what we are going to cover in this section:
Custom Login Form
Form Login and Logout
Remember Me Feature
Thymeleaf Spring Security Dialect
Account & Registration Templates
In this lesson we are going to create our own custom login form.
When we submit a form Spring Security is expecting 2 things from us:
The username must be present as the HTTP parameter named username
The password must be present as the HTTP parameter named password
Since our field is named "email" we just need to add one more configuration to our form login and that is usernameParameter("email")
When using the WebSecurityConfigurerAdapter, logout capabilities are automatically applied. The default is that accessing the URL /logout will log the user out by:
Invalidating the HTTP Session
Cleaning up any RememberMe authentication that was configured
Clearing the SecurityContextHolder
Redirect to /login?logout
Similar to configuring login capabilities, however, you also have various options to further customize your logout requirements:
Remember-me or persistent-login authentication refers to web sites being able to remember the identity of a principal between sessions.
In Spring MVC environments, the Spring Security integration module works as a replacement of the Spring security taglib.
We use this dialect in the example in order to print the logged user credentials and to show different content to different roles.
One thing that I noticed is that we never updated the display to show who actually submitted the link. In this lesson we will fix this issue up on the home page and the view link page.
In this lesson we are going to update the templates for Register and Profile so that they display correctly. We aren't going to actually make these work right now but we do want to see them load.
In this lesson we are going to wrap up the Spring Security View layer and merging the security section back into master.
This course offers hands-on experience building Spring Framework applications using Spring Boot. The first thing that is going to stand out is that we are going to move away from the boring, non-useful demos. In the new course, we are going to build a practical application from start to finish.
While we are creating this application together we will take a look at some of the new features Spring Framework 5 & Spring Boot 2 have to offer. By taking this course you will have the latest skills that you need to build real applications using the Spring Framework.
What is Spring Boot?
Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications that you can "just run".
Spring Boot takes an opinionated view of the Spring platform and third-party libraries so you can get started with minimum fuss. Most Spring Boot applications need very little Spring configuration.
Build anything with Spring Boot
Spring Boot is the starting point for building all Spring-based applications. Spring Boot is designed to get you up and running as quickly as possible, with minimal upfront configuration of Spring.
Get started in seconds using Spring Initializr
Build anything - REST API, WebSocket, Web, Streaming, Tasks, and more
Simplified Security
Rich support for SQL and NoSQL
Embedded runtime support - Tomcat, Jetty, and Undertow
Developer productivity tools such as live reload and auto restart
Curated dependencies that just work
Production-ready features such as tracing, metrics and health status
Works in your favorite IDE - Spring Tool Suite, IntelliJ IDEA and NetBeans