2. Who invented Spring Framework
• Rod Johnson
• Spring (previously known as SpringSource) was a software company
founded by Rod Johnson, who also created the Spring Framework, an
open-source application framework for enterprise Java applications.
3. What is the basic concept of Spring?
• Spring is considered to be a secure, low-cost and flexible
framework that improves coding efficiency and reduces
overall application development time through efficient use of
system resources.
• Spring removes tedious configuration work so that developers
can focus on writing business logic
4. What is Spring used for?
• It helps application developers to perform the following functions:4
• Create a Java method that runs in a database transaction with no
help from transaction APIs.
• Create a local Java method that defines a remote procedure with no
help from remote APIs.
5. How to use Spring Framework?
• Create the Bean. java class.
• Create a XML/ configuration file.
• Create the main class.
• Load the required jar files.
• Run the application.
6. Why to Learn Spring?
• Spring is the application development framework for enterprise Java.
• to create high performing, easily testable, and reusable code.
• Spring framework is an open source Java platform. It was initially written by Rod
Johnson and was first released under the Apache 2.0 license in June 2003.
• Spring is lightweight when it comes to size and transparency. The basic version of
Spring framework is around 2MB.
• Spring framework targets to make J2EE development easier to use and promotes
good programming practices by enabling a POJO-based programming model.
• Plain old Java object (POJO) is a class definition
7. What is POJO and why it is used?
•POJO stands for Plain Old Java Object.
•It is used to describe a Java class that follows simple
conventions and does not depend on any specific
frameworks or libraries.
•A POJO typically contains private fields with corresponding
getter and setter methods, and it may also include additional
methods for behaviour.
8. Differences Between POJO and Java beans
• POJO can have other than private fields whereas Java beans
can only have private fields.
• POJO may or may not have a constructor whereas Java
beans should have a no-argument constructor.
9. public class test implements Serializable
{
private String a;
public test(){}
public String getA()
{return a;}
public void setA(String a)
{this.a=a;}
}
Example java Bean & POJO
10. Applications / benefits of Spring
• POJO Based - Spring enables developers to develop enterprise-class
applications using POJOs.
• The benefit of using only POJOs is that you do not need an EJB
container product such as an application server but you have the
option of using only a robust servlet container such as Tomcat or
some commercial product.
• Modular - Spring is organized in a modular fashion. Even though the
number of packages and classes are substantial.
11. Applications / benefits of Spring
• Integration with existing frameworks
• Testablity - Testing an application written with Spring is simple
because. environment-dependent code is moved into this
framework
• By using JavaBeanstyle POJOs, it becomes easier to use dependency
injection for injecting test data.
• Web MVC - which provides a great alternative to web frameworks
such as Struts or other over-engineered or less popular web
frameworks.
12. Applications / benefits of Spring
• Central Exception Handling - Spring provides a convenient API to translate
technology-specific exceptions (thrown by JDBC, Hibernate, or JDO, for
example) into consistent, unchecked exceptions.
• Lightweight - Lightweight IoC containers tend to be lightweight, especially
when compared to EJB containers, for example. This is beneficial for
developing and deploying applications on computers with limited memory
and CPU resources.
• Transaction management - Spring provides a consistent transaction
management interface that can scale down to a local transaction (using a
single database, for example) and scale up to global transactions (using JTA,
for example).
13. Spring's Inversion of Control (IoC) container
• It is responsible for instantiating, configuring
and assembling objects known as beans, as well
as managing their life cycles
14. Dependency Injection (DI)
• Dependency Injection (DI) is a design pattern used to implement IoC.
• It allows the creation of dependent objects outside of a class and
provides those objects to a class through different ways.
• It removes the dependency of the programs. In such case we provide
the information from the external source such as XML file.
• It makes code loosely coupled and easier for testing.
• Using DI, we move the creation and binding of the dependent
objects outside of the class that depends on them.
15. The Dependency Injection pattern involves 3
types of classes.
• Client Class: The client class (dependent class) is a class which
depends on the service class
• Service Class: The service class (dependency) is a class that provides
service to the client class.
• Injector Class: The injector class injects the service class object into
the client class.
• The following figure illustrates the relationship between these
classes:
16. Types of Dependency Injection
• the injector class injects the service (dependency) to the client
(dependent).
• The injector class injects dependencies broadly in three ways:
• through a constructor,
• through a property, or
• through a method.
23. What is difference between jar and WAR
files?
• JAR files are used for packaging and distributing
standalone Java applications or libraries,
• WAR files are used for packaging and distributing web
applications.
• Web-based applications need an internet connection,
servers, and any additional resources to run but
• Standalone applications do not require any additional
resources such as an internet connection, server, etc.
• Ex: Desktop software, Mobile apps, Gaming Applications, Industrial control
systems Medical Devices, etc.
24. Domain Specific Language (DSL)
• Domain Specific Language (DSL) is a specialized
programming language that's used for a single
purpose.
• Example - DSLs include: SQL (used for database
queries and data manipulation)
• Ex: CSS, regular expressions, make, ant, SQL, many
bits of Rails, expectations in JMock, graphviz's dot
language, strut's configuration file....
25. What is the basic introduction
of Maven in Spring Boot?
26. Maven
• Maven is a Build automation/Project management tool while Spring boot
provides RAD (Rapid Application Development) feature for applications using
spring framework.
• You can build spring boot applications using Maven, Gradle, SBT (If using
scala) and a lot of other build automation tools.
• The Spring Boot Maven Plugin provides Spring Boot support in Apache
Maven.
• It allows you to package executable jar or war archives, run Spring Boot
applications, generate build information and start your Spring Boot
application prior to running integration tests.
• Maven might be best for small projects,
• while Gradle is best for bigger projects.
27. Why Maven?
• do not want to keep all of your libraries in your project!
28. What is Gradle?
• Gradle is a build automation tool that is commonly used to build
software.
• A build automation tool is used to automate the creation of
applications, that includes everything from compiling to packaging
the code, making the process more consistent.
29. Basis Gradle Maven
Based on
Gradle is based on developing domain-specific language
projects.
Maven is based on developing pure Java
language-based software.
Configuration
It uses a Groovy-based Domain-specific language(DSL) for
creating project structure.
It uses Extensible Markup Language(XML) for
creating project structure.
Focuses on Developing applications by adding new features to them. Developing applications in a given time limit.
Performance
It performs better than maven as it optimized for tracking only
current running task.
It does not create local temporary files during
software creation, and is hence – slower.
Java Compilation It avoids compilation. It is necessary to compile.
Usability
It is a new tool, which requires users to spend a lot of time to
get used to it.
This tool is a known tool for many users and is
easily available.
Customization This tool is highly customizable as it supports a variety of IDE’s.
This tool serves a limited amount of developers
and is not that customizable.
Languages supported It supports software development in Java, C, C++, and Groovy.
It supports software development in Java, Scala,
C#, and Ruby.
Project Configuration
For declaring the project configuration, it does not use the
XML files.
For declaring the project configuration, it uses
the XML files.
Based on Graph of task dependencies that do the work. On the phases of the fixed and linear model.
Goal
To add functionality in the project is the main goal of the
Gradle.
To finish the project in the given timeline is the
main goal of the Maven.
30. What is a POM xml?
• A Project Object Model or POM is the fundamental
unit of work in Maven.
• It is an XML file that contains information about the
project and configuration details used by Maven to
build the project.
31.
32. What is the difference between POM and
POM xml?
• POM stands for Project Object Model, and it is the core of a project's
configuration in Maven.
• It is a single configuration XML file called pom.
• xml that contains the majority of the information required to build a
project.
33. Is POM xml required?
• xml is required for building project using Maven.
• You might import jars manually in eclipse but for building the project
in some other build system which supports Maven, you would need
pom
34. Advantages of Spring Framework
• It is lightweight in nature due to its POJO implementation which
doesn’t force to inherit any class or implement any interfaces.
• Spring Framework supports other frameworks and its integration
makes Spring easier to develop.
• The Spring application is loosely couple due to Dependency Injection.
• The Spring Framework is easier to test and it doesn’t require any
server to run the application.
• It provides a powerful abstraction to JavaEE Specifications like JDBC,
JTA etc.
• Spring can remove the creation of the singleton and factory classes.
• Spring framework takes the best practices in all applications and
formalizes as design patterns.
35. Disadvantages of Spring Framework
• Complexity
• Parallel Mechanism: It provides multiple options to developers. These
options create confusion to developers that which feature to use and
which to not and wrong decisions may lead to significant delays.
• No Specific Guidelines: It does not care about XSS or cross-site
scripting.
• High Learning Curve: If you have not development experience in the
field, it would be quite difficult to learn It is difficult due to new
programming methods.
• Lots of XML: Developing a Spring application requires lots of XML.
36. Annotations in Java
• Annotations in Java provide additional information to the
compiler and JVM.
• An annotation is a tag representing metadata about classes,
interfaces, variables, methods, or fields.
• Annotations do not impact the execution of the code that they
annotate.
• Annotations start with @.
Its syntax is:
@AnnotationName
37. Spring Boot Annotations
• Spring Boot Annotations is a form of metadata that provides
data about a program.
• annotations are used to provide supplemental information
about a program.
• It is not a part of the application that we develop.
• It does not have a direct effect on the operation of the code
they annotate.
• It does not change the action of the compiled program.
38. @Controller / @RestController
• @Controller is a class-level annotation.
• It is a specialization of @Component.
• It marks a class as a web request handler.
• It is often used to serve web pages.
• By default, it returns a string that indicates which route to
redirect.
• It is mostly used with @RequestMapping annotation.
39. @GetMapping(“/hello”)
• The @GetMapping(“/hello”) tells Spring to use our hello() method to
answer requests that get sent to the http://localhost:8080/hello
address.
• @GetMapping: It maps the HTTP GET requests on the specific
handler method.
• It is used to create a web service endpoint that fetches It is used
instead of using:
@RequestMapping(method = RequestMethod.GET)
40. @ResponseBody
• The @ResponseBody annotation tells a controller
that the object returned is automatically serialized
into JSON and passed back into the HttpResponse
object.