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.
  • Lectures 174
  • Video 28 Hours
  • Skill level expert level
  • Languages English
  • Includes Lifetime access
    30 day money back guarantee!
    Available on iOS and Android
    Certificate of Completion

How taking a course works

Discover

Find online courses made by experts from around the world.

Learn

Take your courses with you and learn anywhere, anytime.

Master

Learn and practice real-world skills and achieve your goals.

Course 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.

What are the 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

What am I going to get from this course?

  • Over 174 lectures and 28 hours of content!
  • 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

What is the target audience?

  • Java developers
  • Anyone with some fluency in Java and an interest in web or database programming

What you get with this course?

Not for you? No problem.
30 day money back guarantee

Forever yours.
Lifetime access

Learn on the go.
Desktop, iOS and Android

Get rewarded.
Certificate of completion

Curriculum

Section 1: Getting Started
06:30
In this video we'll start by discussing what you can use Spring for and what Spring actually is.
15:54
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.
13:31
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.
08:45
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.
21:10
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.
05:12
We can load Spring XML files from anywhere on the classpath; we'll see how to do it here.
Section 2: Basic Bean Configuration
08:16
In this tutorial we'll take a look at how we can supply arguments to the constructors of our Spring beans via XML.
07: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.
11:39
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.
04:25
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.
08:47
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.
13:03
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
05:30
Yes, it sounds like something terrible from theoretical physics, but actually it's a simple way of setting bean properties with minimal typing
05:48
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.
05:21
What if you need to pass a bean a whole list of other beans? Once again it's quite simple.
03:51
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.
04:05
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.
05:40
Now it's time to look at setting a an arbitrary Map as the property of a bean.
Section 3: Autowiring
08:41
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
05:55
We can also autowire our Spring beans by matching their names or Ids to the names of set methods.
04:18
Spring lets us autowire constructors by matching types of beans to constructor parameters.
07:29
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.
04:49
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.
Section 4: Wiring with Annotations
05:44
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.
07:54
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.
02:34
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 …
07:59
The @Qualifier annotation enables us to further narrow the bean selection considered by Autowired.
03:58
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.
02:20
We can use some JSR-250 annotations to specify init and destroy methods.
04:58
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.
04:48
We can ditch the XML and tell Spring which classes are to be used to create beans just using annotations.
03:42
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.
Section 5: Spring Expression Language (SPEL)
13:29
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.
05:16
We can use SPEL with annotations too; the “Value” annotation will accept SPEL expressions.
07:29
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.
Section 6: Working with Databases
14:30
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.
08:50
Since we'll need to store database connection info in a config file, let's take a look at reading property files in Spring.
04:29
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.
03:06
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.
11:46
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.
04:44
We use various “JDBC Templates” in Spring to run SQL. In fact, we'll mostly get by using the simplest variety.
12:08
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.
06:18
Spring saves us from having to handle millions of JDBC exceptions; but we can still handle them when we want to.
10:12
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.
05:11
It's very easy to execute SQL update statements in Spring; in this tutorial we'll implement a “delete” method.
08: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.
06:30
For the sake of completeness, we'll add a “update” method to our DAO in this tutorial.
11:39
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.
11:58
Of course we can also do transactions in Spring, enabling us to run a bunch of statements in a failsafe manner.
Section 7: Web Application Basics with Spring MVC
08:18
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.
05:37
The next step is to add Maven support to our Eclipse project and bring in the necessary Spring jars.
12:17
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.
07:21
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.
08:55
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.
07:49
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.
12:15
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.
10:08
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.
21:28
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.
07:29
Now we can copy over our DAO code from previous tutorials and configure a context container (XML file) to create the necessary beans.
09:27

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.

06:16
Spring has a special tag which sets up a data source bean for us that will connect to our JNDI data source.
15:00
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.
11:24
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.
05:58
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.
Section 8: Working with Web Forms
11:29
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.
05:39
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.

09:38
Let's add a few CSS styles so that the form looks a little bit less ugly.
10:03
We can get our DispatcherServlet to serve static content, such as a CSS stylesheet or images.
13:00
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.
07:43
Let's finish adding validation tags to our form.
08:45
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.
06:31
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.
18:42
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.
10:10
Let's wire our database code into our controller now, so that our form actually does something useful.
12:42
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.
Section 9: Aspect-Oriented Programming (AOP)
08:33
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.
13:01
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 :)
12:34
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 ...
Wildcards in Pointcut Expressions
15:27
11:03
“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.
12:48
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.
03:55
In this tutorial we'll see a new way of defining pointcuts, using “within” instead of “execution”.
08:21
We'll look at two more pointcuts designators in this tutorial; “this” and “target”.
13:16
There are a bunch of Point Cut Designators (PCDs) that are designed to target annotations; we'll explore them in this tutorial.
02:41
The Bean PCD lets you target beans, and supports asterisk wildcards.
07:43
“Args” lets you match methods based on argument types; it's fairly straightforward, although there are a few complications, as we'll see.
03:02
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.
06:54
We can also get method arguments using the binding form of “args”, which we'll take a look at here.
06:06
You can combine multiple pointcut designators in a single powerful expression.
10:55
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.
Section 10: Spring Security and Managing Users
09:02
Let's start by reviewing what a “filter” is and how it works.
09:43
We'll start adding security to our website by adding a Spring filter that will monitor all incoming requests.
17:24
Now we can set up a Spring default login form, allowing people in only when they type the correct user name and password.
02:49
Using what we've already learned, we can easily add some access rules to serve static content such as CSS files and images.
09:50
We can supply our own login form to replace the default Spring one, which we can then customise to our hearts' content.
09:03
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.
13:35
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.
16:07
Let's add a form that allows people to create new users, in other words, to register on our website.
18:20
No new Spring stuff in this tutorial, but we'll add database-related code to made the user creation form work.
17:30
We'll add validation to “User” in this tutorial; once again, no new Spring stuff, but we'll apply stuff we've previously learned.

Instructor Biography

John Purcell , 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. I now live in the beautiful city of Budapest, Hungary, from where I run the website Cave of Programming.

Join the biggest student community

6,400,000

Hours of video content

29,000,000

Course Enrollments

7,900,000

Students

Reviews

Average Rating
4.8
Details
  1. 5 Stars
    258
  2. 4 Stars
    23
  3. 3 Stars
    5
  4. 2 Stars
    4
  5. 1 Stars
    4
    • Vimal David

    Interesting and engaging

    The course is informative and engaging. Will recommend to friends.

    • Anushabalaji

    The content is informative.The instructor's delivery is engaging and interesting

    • Thanh Binh

    thanks John

    Your are the best teacher that I found. Your course is very useful and enough. This is the best course that I found.

    • Aayush Mittal

    I never buy courses online but this one is totally worth every penny!

    Amazing instructor. Love the way he has covered minute details and made this framework easy to learn.

    • Rocky

    Excellent

    Very good content and presentation. John walks you through !!

Show more reviews
Ready to start learning?
Preview this course