Professional Documents
Culture Documents
Spring Tutorial - Day1
Spring Tutorial - Day1
Container: Spring Framework creates and manages the life cycle and
configuration of application objects.
Since its origin till date, Spring has spread its popularity across various domains.
Spring Framework now is the foundation for various other Spring Projects that
have come up in the offerings in the last two to three years. Check the below
image to find out various projects undertaken by Spring.
Let’s now explore these modules in details. I will start with the Core Container on
which rest of the modules are constructed, then I’ll talk about Data Access
followed by Web and AOP. Finally, I will discuss on some of the miscellaneous
modules.
Spring Tutorial: Modules Of Spring Framework
Core Container
1. Spring Core: This module is the core of the Spring Framework. It provides
implementation for features like IoC (Inversion of Control) and
Dependency Injection with singleton design pattern.
2. Spring Bean: This module provides implementation for the factory design
pattern through BeanFactory.
3. Spring Context: This module is built on the solid base provided by the
Core and the Beans modules and is a medium to access any object
defined and configured.
4. Spring Expression Languages (SpEL): This module is an extension to
expression language supported by Java server pages. It provides a
powerful expression language for querying and manipulating an object
graph, at runtime.
1. JDBC: This module provides JDBC abstraction layer which eliminates the
need of repetitive and unnecessary exception handling overhead.
2. ORM: ORM stands for Object Relational Mapping. This module provides
consistency/ portability to our code regardless of data access technologies
based on object oriented mapping concept.
3. OXM: OXM stands for Object XML Mappers. It is used to convert the
objects into XML format and vice versa. The Spring OXM provides an
uniform API to access any of these OXM frameworks.
4. JMS: JMS stands for Java Messaging Service. This module contains
features for producing and consuming messages among various clients.
5. Transaction: This module supports programmatic and declarative
transaction management for classes that implement special interfaces and
for all your POJOs. All the enterprise level transaction implementation
concepts can be implemented in Spring by using this module.
Spring Web
Instrumentation
Test
Instructor-led Sessions
Real-life Case Studies
Assignments
Lifetime Access
Explore Curriculum
This module supports the testing of Spring components with JUnit or TestNG. It
provides consistent loading of Spring ApplicationContexts and caching of those
contexts. It also provides mock objects that we can use to test our code in
isolation.
In order to create your application you might need the help of IDE (Integrated
Development Environment). An IDE is a software application that provides
comprehensive facilities to the programmers for software development. There
are various IDE’s available in the market, here I am using the Eclipse
IDE because it’s very convenient to use. So now let’s see how to install IDE and
start programming.
You may go through the webinar recording of Spring Tutorial where our instructor
has explained the topics in a detailed manner that will help you to understand
Spring Framework better.
Spring Tutorial For Beginners With Examples | Edureka
Spring Tutorial: IDE Installation
Note: Before you start installing IDE, you need to have Java installed in your
system. In case you want to install Java, refer to this blog.
1. Go to www.eclipse.org.
2. Download Eclipse Neon installer and install it on your Windows system.
3. Now you have to install Spring plugin. For that go to Help > Eclipse
Marketplace.
4. You have to type Spring in the search bar.
5. Click on “Install”.
6. Now you have to click on “Confirm” to proceed with the installation.
7. Let the installation finish, then restart the eclipse although it will
automatically ask for it.
1
2 package org.edureka.firstSpring;
public class StudentBean
3 {
4 String name; public String getName()
5 { return name; }
6 public void setName(String name)
7 { this.name = name; }
public void displayInfo()
8 { System.out.println("Hello: "+ name); }
9 }
10
This is a simple bean class, containing only one property name with its
getters and setters method. This class contains one extra method named
displayInfo() that prints the student name by the hello “student name”
message.
Right click on src > New > Other > XML File
<?xml version="1.0" encoding
1 <beans xmlns="http://www.springframework.org/schema/beans" xmlns:
2 xmlns:p="http://www.springframework.org/schema/p" xsi:schemaLocati
3 http://www.springframework.org/schema/bean
4
5 <bean id="studentbean" class="org/edureka/f
6 <property name="name" value="Edure
</bean>
7 </beans>
The <bean> tag is used to define the bean for the given class.
1
2 package org.edureka.firstSpring;
3 import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationCont
4 public class StudentDemo
5 {
6 public static void main(String[] args)
7 {
8 ApplicationContext appCon=new ClassPathXmlApplicationContext("StudentConfi
StudentBean factory=(StudentBean)appCon.getBean("studentbean");
9 factory.displayInfo();
10 }
11 }
12
Step IV: Load the jar files
Here is the list of the jar files needed. You have to download it and add it to
your library.
NOTE: In case you want jar files, you can comment below.
You can now test your code by running the StudentDemo class. You can
see in the below output that the name Edureka is injected by the
ApplicationContext at the run-time. Likewise you can change the name any
time you want, just by changing the name in the configuration file.
Spring Tutorial: Spring IoC Container
Since we are done with the first basic program, I hope you have got an idea
about Spring Framework. Let’s now discuss on some of the concepts working at
the core of Spring Framework. We will begin with IoC container.
So what exactly is an IoC container in Spring? Well, Spring IoC stands for
Inversion of Control. It is the heart of the Spring Framework. The important tasks
performed by the IoC container are: