Spring MVC Framework: Mohit Gupta
Spring MVC Framework: Mohit Gupta
Spring MVC Framework: Mohit Gupta
Mohit Gupta
Agenda
1. Framework
2. OOPS Concepts
3. Spring
4. JSP & Servlets
5. Loggers
6. ANT Tool
7. Web Services
August 1, 2016
2
What is a Framework ?
Hotel
Without Framework
With Framework
OOP Concepts since JAVA is a OOP
Language
August 1, 2016
5
August 1, 2016
6
Platform Independence
August 1, 2016
7
Spring Overview
Spring Overview
• Very pluggable
• Examples:
• Spring, Pico
• Hibernate, IBatis
Spring 3.0 MVC- Basic Architecture
HandlerMapping
(Map of URL and
2 controllers)
Controller
(Responsibl
Request Dispacth
3
e to handle
1 erServlet request)
(Front controller)
4
5 Model
View (JSP, (POJO
XML, Beans)
Velocity)
Flow diagram Spring framework
August 1, 2016
12
Overview of the Spring Framework
This framework has very loosely coupled components which are widely reusable
and are packaged separately.
Modules of the Spring Framework
The Spring Framework can be considered as a collection of frameworks-
in-the-framework:
1. Core - Inversion of Control (IoC) and Dependency Injection
2. AOP - Aspect-oriented programming
3. DAO - Data Access Object support, transaction management, JDBC-
abstraction
4. ORM - Object Relational Mapping technique for converting data b/w
incompatible type system in OOP language.
5. MVC - Model-View-Controller implementation for web-applications
6. Remote Access, Authentication and Authorization, Remote Management,
Messaging Framework, Web Services, Email, Testing, …
Bean
class MyBean {
private int counter;
• Rather than locating needed resources, application components provide getter &
setter methods through which resources are passed in during initialization
• In Spring Framework, this pattern is used extensively, and initialization is usually
done through configuration file(web.xml) rather than application code
Example of BEAN Class
• package player;
public PersonBean() {
}
/**
* Setter for property */
public void setName(final String value) {
name = value;
}
@Configuration
public class AppConfig { @Bean publicTransferService transferService() { return new
TransferServiceImpl(); } }
The above is exactly equivalent to thefollowing appConfig.xml:
<beans><bean name="transferService" class="com.acme.TransferServiceImpl"/> </beans>
August 1, 2016
17
Dependency Injection -Inversion of
Control (IoC)
• All together form the object lifecycle which is one of the most important
features
Dependency Injection-Container resolves (injects)
dependencies of components by setting implementation
object during runtime
Draw()
Circle
Triangle
During Implementation
Dependency Injection - IoC
• Beans define their dependencies through constructor arguments or properties
• Container resolves (injects) dependencies of components by setting
implementation object during the runtime
• BeanFactory interface – It is the core that
loads bean definitions and manages beans
• Most commonly used implementation
is the XmlBeanFactory class
• It allows you to express the objects that compose
application, and the interdependencies
between such objects, in terms of XML
• The XmlBeanFactory takes this XML
configuration metadata and uses it to create a fully configured system
Spring Solutions
Level Description
DEBUG Designates fine-grained informational events that are most useful to debug
an application.
ERROR Designates error events that might still allow the application to continue
running.
FATAL Designates very severe error events that will presumably lead the
application to abort.
OFF The highest possible rank and is intended to turn off logging.
August 1, 2016
28
August 1, 2016
29
Types of Layouts
1. DateLayout
2. HTMLLayout
3. PatternLayout
4. SimpleLayout
5. XMLLayout
• Using HTMLLayout and XMLLayout, you can generate log in HTML and in
XML format as well.
August 1, 2016
30
ANT-Build Tool
• ANT stands for Another Neat Tool. It is a Java-based build tool from
Apache.
• Need for a Build Tool (DEV OPS)
• On an average, a developer spends a substantial amount of time
doing mundane tasks like build and deployment that include:
• Compiling the code
• Packaging the binaries
• Deploying the binaries to the test server Testing the changes
• Copying the code from one location to another
• To automate and simplify the above tasks, Apache Ant is useful. It is
an Operating System build and deployment tool that can be executed
from the command line.
August 1, 2016
31
What is the use of the build.xml file?
The build.xml file is an Ant script that is created by the Plug-in Development Environment (PDE) to
take your plug-in components and combine them into a deployable format.
This file compiles and archives your plug-in source code into a single JAR file.
The build.properties file controls what goes into your plug-in distribution.
The build.xml file can be created by using the context menu on plugin.xml and selecting PDE Tools >
Create Ant Build File.
Ant build files are low-level mechanisms to package up plug-ins. A much easier way to share and
deploy plug-ins is to create a feature for your plug-in and then an update site.
August 1, 2016
32
Build path vs Class Path
August 1, 2016
33
What is the difference between EAR, JAR and
WAR file
JAR
EJB modules which contains enterprise java beans class files
and EJB deployment descriptor are packed as JAR files with
.jar extenstion
WAR
Web modules which contains Servlet class files,JSP
FIles,supporting files, GIF and HTML files are packaged as
JAR file with .war( web achive) extension
EAR
All above files(.jar and .war) are packaged as JAR file with
.ear ( enterprise archive) extension and deployed into
Application Server.
August 1, 2016
34
August 1, 2016
35
WEB SERVICES
Web service is a technology to communicate one
programming language with another. For example, java
programming language can interact with PHP and .Net by
using web services. In other words, web service provides a
way to achieve interoperability.
SOAP & REST Webservices
August 1, 2016
36
Advantages Of MVC Framework
August 1, 2016
37
Advantages of Spring Architecture
• Enable you to write powerful, scalable applications using POJOs
• Lifecycle – responsible for managing all your application components, particularly those in
the middle tier container sees components through well-defined lifecycle: init(), destroy()
• Dependencies - Spring handles injecting dependent components without a component
knowing where they came from (IoC)
• Configuration information - Spring provides one consistent way of configuring everything,
separate configuration from application logic, varying configuration
• In J2EE (e.g. EJB) it is easy to become dependent on container and deployment
environment; Spring eliminates them
• Portable (can use server-side in web/ejb app, client-side in swing app, business logic is
completely portable)
• Thank You
August 1, 2016