The Java Spring Tutorial: Learn Java's Popular Web Framework
4.3 (3,025 ratings)
Instead of using a simple lifetime average, Udemy calculates a course's star rating by considering a number of different factors such as the number of ratings, the age of ratings, and the likelihood of fraudulent ratings.
24,990 students enrolled
Wishlisted Wishlist

Please confirm that you want to add The Java Spring Tutorial: Learn Java's Popular Web Framework to your Wishlist.

Add to Wishlist

The Java Spring Tutorial: Learn Java's Popular Web Framework

Learn the hottest, most in-demand Java web framework, including web programming with Spring MVC and Hibernate. Lifetime access with no subscription on Udemy.
4.3 (3,025 ratings)
Instead of using a simple lifetime average, Udemy calculates a course's star rating by considering a number of different factors such as the number of ratings, the age of ratings, and the likelihood of fraudulent ratings.
24,990 students enrolled
Created by John Purcell
Last updated 1/2016
English
English
Current price: $10 Original price: $35 Discount: 71% off
4 days left at this price!
30-Day Money-Back Guarantee
Includes:
  • 28 hours on-demand video
  • 5 Articles
  • 1 Supplemental Resource
  • Full lifetime access
  • Access on mobile and TV
  • Certificate of Completion
What Will I Learn?
  • Understand the fundamentals of the Java Spring framework
  • Learn how to develop web and database applications with Spring
  • Understand the basics of Hibernate for SQL-free database connectivity
View Curriculum
Requirements
  • Fair knowledge of the Java programming language
  • Knowledge of HTML, servlets and JSPs is recommended for the web section of this tutorial
  • Some acquaintance with XML is helpful
  • Knowledge of SQL and databases is helpful for the database-related parts of this tutorial
Description

An introduction to the widely-used Java Spring framework. Discover how to wire together your Java objects using Spring and dependency injection. You'll learn how to set up your system for Spring development, how to use Maven, and how to work with databases using Spring and Hibernate and how to create web applications with Spring MVC. We'll also look at managing user accounts with Spring Security,JDBC, working with web forms, Apache tiles for building modular web pages, aspect-oriented programming (AOP) and using Log4J and JUnit.

Who is the target audience?
  • Java developers
  • Anyone with some fluency in Java and an interest in web or database programming
Students Who Viewed This Course Also Viewed
Curriculum For This Course
176 Lectures
27:47:16
+
Getting Started
7 Lectures 01:11:02
In this video we'll start by discussing what you can use Spring for and what Spring actually is.
Preview 06:30

Please see the attached PDF if you want to use Spring 4.2+ for this course.

Preview 2 pages

How to set up your system for Spring development, installing Java, Eclipse EE, Maven, the m2e Maven Eclipse plug, the Spring IDE Eclipse plugin, and optionally Tomcat if you want to get into web development.
Preview 15:54

In this video we'll take a look at Maven; what it is, basic usage, and how to create a basic Maven project. We'll only need a basic knowledge of Maven to do everything we want to do later on with Spring, in fact. This tutorial assumes you've installed the Maven Integration for Eclipse plugin as described in the previous tutorial, and that you have a connection to the Internet.
Preview 13:31

A tutorial on creating Maven projects from the command line. This is an optional video in this course; we won't actually need to use Maven from the command line, but seeing what's possible using “pure” Maven will help you to understand Maven, and for that reason I've created this tutorial.
Preview 08:45

Creating a simple “hello world” project in Spring. Yes, finally it's time to create an actual Spring project, now that we've got our system set up.
Preview 21:10

We can load Spring XML files from anywhere on the classpath; we'll see how to do it here.
Preview 05:12
+
Basic Bean Configuration
12 Lectures 01:23:41
In this tutorial we'll take a look at how we can supply arguments to the constructors of our Spring beans via XML.
Preview 08:16

Of course it's possible to set properties of beans in Spring from XML; that is, we can invoke set methods of our objects and pass values to them which we code into the XML.
Preview 07:16

Dependency Injection is one of the buzzwords for which Spring is famous. It sounds ferocious, but it isn't at all complicated. Here we'll take a look at how we can inject a Spring bean with another bean, allowing you to configure your beans with whatever services or facilities take your fancy – provided you've got the functionality you need in another bean somewhere, of course.
Preview 11:39

Beans have a scope; for our purposes here, the choice we have is between reusing our one and only bean or creating new beans to order.
Bean Scope
04:25

Beans in Spring have a distinct lifecycle, and we can make code run when beans are created or destroyed. Finally a reliable “destructor” in Java! Well, sort of.
Init and Destroy Methods
08:47

Sometimes you want to create objects via a factory method or class rather than via a public constructor. Spring makes it easy to do this through your application contexts
Factory Beans and Methods
13:03

Yes, it sounds like something terrible from theoretical physics, but actually it's a simple way of setting bean properties with minimal typing
The P Namespace
05:30

If you need to set a bean property that's actually a list or set of stuff from XML, you can do this too quite easily.
Setting List Properties
05:48

What if you need to pass a bean a whole list of other beans? Once again it's quite simple.
Lists of Beans
05:21

Sometimes you want to define a bean solely for the purpose of passing it to another bean, and you never want to refer to it in your XML again. In that case, maybe you need an inner bean.
Inner Beans
03:51

There's a class in Java called “Properties”, which is basically a kind of Map. In Spring, whenever a bean property expects to be passed a Map, and the keys and values are both Strings, we can use a property map to supply the required map. Don't get confused between a property map, and “properties” meaning the fields of objects (beans). I noticed after making this tutorial that I had initialised my Map property to a new HashMap, which is kind of redundant since Spring will create a new Map; although it does at least allow us to run the toString() method of our bean when it has not had its property map set.
Property Maps
04:05

Now it's time to look at setting a an arbitrary Map as the property of a bean.
Arbitrary Maps as Bean Properties
05:40
+
Autowiring
5 Lectures 31:12
So far we've been wiring our beans manually, but it's also possible to let Spring wire a lot of stuff up automatically. Whether that's necessarily a good idea in a given situation, is another matter. We'll take a look at how to wire stuff up by matching property types to bean types in this tutorial
Autowiring by Type
08:41

We can also autowire our Spring beans by matching their names or Ids to the names of set methods.
Autowiring by Name
05:55

Spring lets us autowire constructors by matching types of beans to constructor parameters.
Autowiring by Constructor
04:18

What if we want to set a default autowiring method for an entire XML container? It's quite easy, and might save us a lot of typing – but be careful to avoid ambiguity and make sure you have all the right beans defined. Autowiring must always be used judiciously.
Default Autowiring
07:29

Spring has a trick or two for removing autowire ambiguities. We can remove beans from our list of possible candidates to autowire into other beans, or we can specify certain beans as primary autowire candidates, to be considered first.
Removing Autowire Ambiguities
04:49
+
Wiring with Annotations
9 Lectures 43:57
XML isn't the only way to configure Spring; these days we can also wire using annotations. In this tutorial we'll adding some stuff to our XML to support annotation-based autowiring.
Adding Support for Annotation-Based Wiring
05:44

The most basic wiring annotation is perhaps the Autowired annotation. We can add this annotation in various locations to our Java code to get Spring to wire up our beans.
The "Autowired" Annotation
07:54

The “required” attribute on @Autowired enables us to specify optional beans. I was a little confused in this video over why Autowired sometimes tolerated ambiguity; now I think a large part of what was happening was that Autowired just decides not to consider a bean a candidate when it's used it once already! One lives and learns …
Optional Beans
02:34

The @Qualifier annotation enables us to further narrow the bean selection considered by Autowired.
Using Qualifiers
07:59

Back in 2006, another annotation was introduced into Java to support dependency injection. We can use it quite happily in Spring, as an alternative to Spring's native Autowired. If you have problems using @Resource, check your project properties and ensure you're building with JDK 1.6 or later.
The Resource Annotation (JSR-250)
03:58

We can use some JSR-250 annotations to specify init and destroy methods.
Annotation-Based Init and Destroy Methods
02:20

Winding forwards to 2009, JSR-330 introduced yet more annotations; @Inject is now one of Java's standard dependency-injection annotations, and of course we can use it in Spring. If you can't find @Inject, make sure you've added the right jar (you can add it via Maven) and ensure that your project is set to build with Java 1.6 or later.
The Inject annotation (JSR-330)
04:58

We can ditch the XML and tell Spring which classes are to be used to create beans just using annotations.
Automatic Bean Discovery
04:48

We can use the @Value annotation to supply values for properties. Later on we'll take a look at SPEL, which will make this a whole lot more interesting.
Setting Property Values via Annotations
03:42
+
Spring Expression Language (SPEL)
3 Lectures 26:14
Spring Expression Language makes property values dynamic, allowing us to run code and figure stuff out when we're busy wiring our beans. We'll also take a look at the “safe navigation” operator.
Introducing SPEL
13:29

We can use SPEL with annotations too; the “Value” annotation will accept SPEL expressions.
Using SPEL with Annotations
05:16

In this tutorial we'll take a look at some useful operators that we can use in SPEL to create new objects, access static methods and perform arithmetical and logical operations.
Some useful SPEL Operators
07:29
+
Working with Databases
14 Lectures 01:59:32
A brief review of how to create a database with MySQL. I won't cover MySQL or SQL in any depth in this tutorial series, but we'll go over the basics.
Creating a Database with MySQL
14:30

Since we'll need to store database connection info in a config file, let's take a look at reading property files in Spring.
Using Property Files
08:50

We'll use the DAO pattern to work with data retrieved from the database in Spring; in this tutorial we'll create a couple of objects that we'll be using a little later on.
Implementing the DAO Pattern
04:29

We'll need a JDBC connector jar to connect to our database. If you're using an open source database like MySQL, you can probably do this via Maven. Otherwise you'll have to do a little Googling for the right jar.
Downloading a Connector Jar
03:06

Usually we use connection pools in Spring when we connect to databases. Later on, when we look at Spring MVC for web applications, we'll use connection pools provided by our application server. Since we're just creating a plan Java app here, we'll need to use an external (free) technology to pool our database connections.
Configuring Connection Pooling with Apache DBCP
11:46

We use various “JDBC Templates” in Spring to run SQL. In fact, we'll mostly get by using the simplest variety.
JDBC Templates
04:44

Finally it's time to do a SQL query on our database. We'll use our JDBC Template to set the properties of a list of DAO beans, corresponding to the rows in our table.
Querying the Database
12:08

Spring saves us from having to handle millions of JDBC exceptions; but we can still handle them when we want to.
Database Exceptions
06:18

While JDBC allows us to use indispensable placeholders in SQL, Spring goes further and lets us used named placeholders, reducing the possibility of bugs and confusion.
Named Parameters
10:12

It's very easy to execute SQL update statements in Spring; in this tutorial we'll implement a “delete” method.
Update Statements
05:11

In this tutorial we'll add a “create” method to our DAO; we'll also see a very nice way of getting values for placeholders directly from your beans.
Getting Placeholder Values from Beans
08:11

For the sake of completeness, we'll add a “update” method to our DAO in this tutorial.
Adding an Update Method to the DAO
06:30

The Spring equivalent of a prepared statement is a batch update. We'll look at running SQL queries with multiple different placeholder values in this tutorial.
Batch Updates: Prepared Statements
11:39

Of course we can also do transactions in Spring, enabling us to run a bunch of statements in a failsafe manner.
Transactions
11:58
+
Web Application Basics with Spring MVC
15 Lectures 02:29:42
We'll start our foray into web apps by creating a non-Spring web app; then we'll Springify it later on. You'll need either Eclipse EE or Eclipse Java IDE + WTP Plugin to get this working, along with a Java application server such as Tomcat.
A Basic Non-Spring Web App
08:18

The next step is to add Maven support to our Eclipse project and bring in the necessary Spring jars.
Bringing in Maven
05:37

The first step towards turning our web app into a Spring web app is to add a dispatcher servlet; this is the Spring servlet that will handle all our requests within the Spring MVC architecture.
The Dispatcher Servlet
12:17

After hitting the dispatcher servlet, requests are routed to a Spring controller in a Spring MVC web app. Here we'll add a single controller.
Adding a Controller
07:21

Finally we can get our Spring web app actually working. In this tutorial we'll add a view resolver that will tell the dispatcher servlet how to interpret the logical view name sent back from our controller.
View Resolvers
08:55

We need to figure out some kind of a way of passing data from our controller to our view, using the soon-to-be-added data model. We'll make a start on it here by looking at how Spring lets us add data to the session.
Adding Data to the Session
07:49

Spring has a bunch of easy-to-use data model classes that will make passing data from the controller to the view code quite simple. We'll take a look at a couple of possibilities in this tutorial.
Using Spring Data Models
12:15

In this tutorial we'll add JSTL support to our application. JSTL lets us use special tags in our HTML to output data, create loops, output stuff conditionally and do lots of other useful stuff, all without mixing up our view code with Java implementation code.
Using JSTL (JSP Standard Tag Library)
10:08

Java application servers like Tomcat provide us with a way of setting up connection pooling; the precise method you need to use to set up and connect to your connection pool depends on your server and database, and your hosting service. Here we'll look at setting up a JNDI data source for Tomcat 7 and MySQL.
Configuring a JNDI Data Source
21:28

Now we can copy over our DAO code from previous tutorials and configure a context container (XML file) to create the necessary beans.
Bringing in the DAO Code
07:29

We can use a special Spring class to load extra XML files. Our configuration for this project is actually going to be split among multiple XML files, which we'll load at startup.

Loading Bean Containers with ContextLoaderListener
09:27

Spring has a special tag which sets up a data source bean for us that will connect to our JNDI data source.
Creating a Datasource Bean
06:16

We're almost ready to display our data via Spring, but first we need a service layer. Our “service” class will simple be a class that's responsible for organising and using our DAOs, instead of cluttering up our controllers with this code.
Adding a Service Layer
15:00

Just a bit of reorganization in this tutorial. We'll add a second controller so that we can have a separate home controller and offer-related controller.
Adding a New Controller
11:24

Spring makes it very easy to get URL parameters. We'll take a look at how to do it here, because it'll be good preparation for getting the results of form submissions later.
Getting URL Parameters
05:58
+
Working with Web Forms
11 Lectures 01:54:22
We'll do a little bit of config in this tutorial, followed by creating an HTML form that we can use to create new “offers” in our database.
Creating a Form
11:29

It's really easy to get the values that the user has entered in a form. Amazingly easy!

Also, Yavuz Yurtbeğendi tells me that you might need the attached XML fragment if you have problems with unicode characters.

Getting Form Values
05:39

Let's add a few CSS styles so that the form looks a little bit less ugly.
Adding CSS Styles
09:38

We can get our DispatcherServlet to serve static content, such as a CSS stylesheet or images.
Serving Static Resources
10:03

By making use of some Hibernate stuff, we can get Spring to validate our form. We'll start by adding some simple validation to one form field.
Adding Hibernate Form Validation Support
13:00

Let's finish adding validation tags to our form.
More Form Validation Tags
07:43

We can easily make our forms redisplay entered values when validation fails, so that the user is not forced to enter everything all over again. To do this, we'll use some special Spring form tags.
Making Forms Remember Values
08:45

It's important to tell the user why a form failed to validate; nothing is worse than not knowing why a form has failed to validate. So let's add some validation error messages to our form.
Displaying Form Validation Errors
06:31

You may never feel the need to create your own custom form validation constraint annotation; after all, regular expressions give you a lot of flexibility. But just in case you want to know how to make a totally new constraint annotation, here's the lowdown.
Creating a Custom Validation Annotation
18:42

Let's wire our database code into our controller now, so that our form actually does something useful.
Hooking Up the Controller and Database Code
10:10

What if our database code throw an exception? Spring makes it easy to handle whichever exceptions you feel like handling. In this tutorial we'll add a page that appears when any database exception is thrown.
Exception Handling in Spring MVC
12:42
+
Aspect-Oriented Programming (AOP)
15 Lectures 02:16:19
We'll create a new project here to experiment with; there's no new Spring stuff in this tutorial, except that we'll add a new dependency, spring-aspects.
A Base Project for Working with Aspects
08:33

Now we can turn our Logger bean from the last tutorial into an “aspect”, containing “advice” which is run at a “join point” specified by a “pointcut”. Phew :)
A Simple Aspect Example
13:01

Annotations being all the rage in Spring these days, let's see how you can do aspect-oriented programming using aspects. As we'll see there are pros and cons to using annotations here, but we'll stick with them in these videos because they at least avoid us having to do loads of XML configuration and take us back towards real programming ...
Annotation-Based Aspects
12:34

Wildcards in Pointcut Expressions
15:27

“Before” advice isn't the only kind of advice we can use. We'll take a look at an arrange of advice types in this tutorial.
Advice Types: After, Around and Others
11:03

It's important to understand the relationship between Spring's proxy objects and the target objects they represent. Otherwise, you'll be prone to casting beans to the wrong type. We'll delve into the mystery and figure out how to avoid problems in this tutorial.
Proxies, Interfaces and Aspects
12:48

In this tutorial we'll see a new way of defining pointcuts, using “within” instead of “execution”.
The “Within” Pointcut Designator
03:55

We'll look at two more pointcuts designators in this tutorial; “this” and “target”.
“This”, “Target” and Matching Subpackages
08:21

There are a bunch of Point Cut Designators (PCDs) that are designed to target annotations; we'll explore them in this tutorial.
Annotation-Specific PCDs
13:16

The Bean PCD lets you target beans, and supports asterisk wildcards.
The “Bean” PCD
02:41

“Args” lets you match methods based on argument types; it's fairly straightforward, although there are a few complications, as we'll see.
The “Args” PCD
07:43

We can get the arguments being passed to our advised methods; there are two good ways to do it, and we'll look at the simplest in this tutorial.
Getting Target Method Arguments
03:02

We can also get method arguments using the binding form of “args”, which we'll take a look at here.
Getting Arguments Using “Args”
06:54

You can combine multiple pointcut designators in a single powerful expression.
Combining Pointcuts
06:06

Aspects allow you to add extra functionality in to your bean proxies. We'll take a look at adding some simple dummy extra functionality to our beans in this tutorial.
Introductions: Adding Functionality Using Aspects
10:55
+
Spring Security and Managing Users
23 Lectures 04:34:08
Let's start by reviewing what a “filter” is and how it works.
Servlets Filters: A Review
09:02

We'll start adding security to our website by adding a Spring filter that will monitor all incoming requests.
Adding a Spring Security Filter
09:43

Now we can set up a Spring default login form, allowing people in only when they type the correct user name and password.
Adding a Spring Login Form
17:24

Using what we've already learned, we can easily add some access rules to serve static content such as CSS files and images.
Serving Static Resources: Access Rules
02:49

We can supply our own login form to replace the default Spring one, which we can then customise to our hearts' content.
Customising the Login Form
09:50

If the user types an incorrect username or password, it'd be good to tell them so. We'll add a login error message to our form in this tutorial.
Displaying Login Errors
09:03

So far we've been hardcoding user names and passwords in our XML config file, but it'd be much better to start this information in a database. One possibility is to use an LDAP database, but here's we'll make use of our existing MySQL database (or we could use any relational database) to store user names and passwords.
Authorising Users from a Database
13:35

Let's add a form that allows people to create new users, in other words, to register on our website.
Adding a “Create Account” Form
16:07

No new Spring stuff in this tutorial, but we'll add database-related code to made the user creation form work.
Making the “Create Account” Form Work
18:20

We'll add validation to “User” in this tutorial; once again, no new Spring stuff, but we'll apply stuff we've previously learned.
Adding Validation to the User Form
17:30

We need to stop users creating multiple accounts with the same user name; actually they already can't since this would violate a database constraint, but we need to catch the error in a more elegant manner.

Dealing with Duplicate Usernames
13:31

We've been hardcoding messages in our Java so far, which is a terrible idea really. Let's move them all into a property file, making it much easier to maintain and alter the messages -- especially if we want to create version of the website in other languages later on.
Storing Validation Messages in a Property File
09:36

Wandering away from Spring slightly, let's use the JQuery javascript library to add some client-side validation to check that the confirmed password matches the actual password.
Using JQuery to verify the password
28:01

We can use some standard JSTL to get error messages from our property file into our Javascript validation code.
Using Property File Values in JSPs
06:39

Since the user can log in, it'd be nice if they can log out too. We'll add such a link in this tutorial.
Adding a Logout Link
06:26

Spring allows us to define “roles” for our users, which determine what they can do. We'll create a new role in this tutorial, allowing privileged users to do some stuff that other users can't.
Working With Roles
09:05

We can output certain links or text on our web pages based on whether the user is logged in or has certain roles or not.
Outputting Text Based on Authentication Status
06:26

Here's a class I really should have mentioned earlier; BeanPropertyRowMapper lets us map queries to beans with a minimum of fuss.
Row Mapping with BeanPropertyRowMapper
11:11

We can use custom SQL to query our user database, allowing us to structure our user database how we want. In this tutorial we'll use it to fix a little problem with the application; user names are not currently case-sensitive, and probably should be.
Using Custom Authentication Queries: Case Sensitive Usernames
05:42

Spring allows us to secure individual methods against unauthorised access; implemented behind the scenes via aspects, this gives us a level of security that's even stronger than url-based security.
Method-Level Access Control
11:28

Spring actually throws an exception if an unauthorised user tries to run a protected method; we can catch the exception with our global handler and redirect to a page of our choice.
Catching Secure Annotation Violations
13:24

We can add a checkbox to our login form that will keep the user logged in for a specified amount of time; this is known as “remember me” functionality. Spring makes it very easy to add such a checkbox!
Adding “Remember Me” Functionality
09:42

Storing passwords unencrypted in the database is a very bad idea, since anyone who has access to the database knows the users' passwords. Much better to encrypt them first, and only store the encrypted version.
Encrypting Passwords
19:34
8 More Sections
About the Instructor
John Purcell
4.4 Average rating
55,625 Reviews
922,158 Students
12 Courses
Software Development Trainer

After working as a software developer and contractor for over 14 years for a whole bunch of companies including CSC, Proquest, SPSS and AT&T in the UK and Netherlands, I decided to work full-time as a private software trainer. After spending four years in the beautiful city of Budapest, Hungary and a year in Berlin, I now live in my home town of Derby, UK.