SlideShare a Scribd company logo
Introduction to Spring MVC
Framework
Tuna Tore
Enroll now to my udemy course
Tuna Tore
https://www.udemy.com/java-spring-mvc-framework-with-angularjs-by-google-and-html5
What is MVC?
 MVC stands for Model View Controller (architecture)
 It is a design pattern used in WEB based JAVA Enterprise
Applications
 MVC pattern is also implemented in other WEB frameworks as well
for separating the model layer from view layer. By doing that UI
programmers and back end developers can work together.
 Model Layer includes business specific logic
 View Layer is responsible for rendering(displaying) model objects
inside the user interface using different view technogies (JSP,
Facelets or Velocity) (browser)
 Controller receives user inputs and calls model objects based on
handler mappings and pass model objects to views in order to
display output inside the view layer.
What is Dependency Injection?
 This is also called as IOC (Inversion of Control Principle)
 It is a software design pattern which is really useful for designing
loosely coupled software components
 You will have more plug-gable and testable code and objects
 It is easy to reuse your code in other applications
 The dependencies won't be hard coded inside all java objects/
classes instead they will be defined in XML configuration files or
configuration classes (Java Config)
 Spring Container is responsible for injecting dependencies of objects
 There are two types of Dependency injection in Spring Framework
Setter Injection and Constructor Injection
Java Spring MVC Framework with AngularJS by Google and HTML5
The general information about web.xml and
Java EE
 The WEB-INF/web.xml is the Web Application
Deployment Descriptor of Java Enterprise Web
applications/
 Inside web.xml, developers can define
Servlets,
Welcome File List
Filters,
Context parameters,
Error pages
Security rights and etc.
The general information about the sample web
application
 Apache Maven Project
 Pivotal tc server
 Java Spring MVC 4.x
version
What is the concept of DispatcherServlet and
how do you configure it?
 DispatcherServlet is configured in order to dispatch
incoming HTTP request to handlers and returns response
to browsers
 Spring MVC is designed around DispatcherServlet
 DispatcherServlet is configured in web.xml file
<servlet>
<servlet-name>dispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-
class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/mvc-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcherServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
What is the concept of DispatcherServlet and
how do you configure it?
 DispatcherServlet is configured in order to dispatch
incoming HTTP request to handlers and returns response
to browsers
 Spring MVC is designed around DispatcherServlet
 DispatcherServlet is configured in web.xml file
<servlet>
<servlet-name>dispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-
class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/mvc-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcherServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
What is ContextLoaderListener and how do you
configure it in Spring MVC?
 ContextLoaderListener is responsible for creating a root
application context in Java Enterprise Web application
inside ServletContext
 Developers can use different controller and view layers
(For example Struts, JSF or Spring MVC can be used)
however Spring Framework will be responsible for
managing services layer or components defined
ContextLoaderListener configuration files
 You can set different configuration XML files in web.xml
http://docs.spring.io/spring/docs/2.5.x/reference/mvc.html
#mvc-servlet
How do you configure controllers in Spring
MVC?
 By extending AbstractController class and
implementing handleRequestInternal method
 By using @Controller or @RestController
annotation on class level
 Controller with bean name URL mapping
 Controller with class name mapping
 Controller with XML config with mappings
How is an incoming request mapped to a
mapped to a method in Spring MVC?
 @RequestMapping is used in order to map incoming
request to a controller using URL matching
 @RequestParam and @PathVariable is used to get
parameters or variable from HTTP request
@RequestMapping(value = "/jdbcDelete/user/{iduser}",
method=RequestMethod.GET)
public ModelAndView jdbcDelete(@PathVariable(value="iduser")
int iduser) {
@RequestMapping(value="/register", method=RequestMethod.POST)
public ModelAndView register(@RequestParam(required=true)
String email,@RequestParam(required=true) String password)
What is a View in Spring MVC? How is the
InternalResourceViewResolver configured?
 Java Spring MVC can be configured with different
view technologies such as Java Server Faces, JSP,
Velocity etc.
 Views are responsible for displaying the content of
Model objects on browsers as response output
 InternalResourceViewResolver is used to resolve
the correct view based on suffix and prefixes so the
correct output (view) is resolved based on strings
Return types from Controllers
You can return the followings from
Controllers
 ModelAndView
 Model
 Map
 View
 String
 void
 HttpHeaders and others
Scopes in Spring MVC
● Default Scope in Spring MVC is request
● Session scope can be used in order to
save the state of beans in web based
applications
● Each time a request send through HTTP a
new bean will be created with request
scope
Application Event Handling
● Developers can handle application events by
implementing
ApplicationListener<ApplicationEvent>
● Customs events can be published by using
application context and extending
ApplicationEvent class
Spring MVC File Upload
● In order to upload a file with Java Spring MVC
<!-- File Upload bean config-->
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartRe
solver">
<!-- set the maximum file size in bytes -->
<property name="maxUploadSize" value="1000000"/>
</bean>
@Controller
public class FileUploadController {
@RequestMapping(value="/uploadFile", method=RequestMethod.POST)
public @ResponseBody String
handleFileUpload(@RequestParam("file") MultipartFile file){
Quartz Scheduling Framework and Spring
Schedules
 Quartz is an alternative to Spring Schedules
and has more functionality
 In order to use Quartz; Triggers, Jobs, Tasks
and Scheduler have to defined in XML
configuration
 Spring Schedules can be configured using
@Scheduled annotation
 @Scheduled(cron="0/30 * * * * ?") or
@Scheduled(fixedDelay = 10000) can be
applied to schedules
Logging in Spring MVC
● LOGBack framework will be used in order to log outputs
● LOGBack is a significantly improved version of log4j
logging framework
● Both log4j and logback were founded with the same
developer
● It is easy to switch logging technologies by using
LOGBack
● The configuration is done through logback.xml
● By default Spring Framework use commons-logging
so dependencies should be excluded in pom.xml
Apache Maven
● Apache Maven is a build automation and
dependency management tool
● Apache Maven is configured using
pom.xml file
● Maven is integrated into Eclipse or STS
JPA and Hibernate ORM
● JPA stands for Java Persistence API
● Hibernate ORM is an implementation of JPA
● ORM stands for Object Relational Mapping
● Hibernate ORM uses @Entity annotation to manage
classes in ORM framework
● @Table(name="USER") is used to map Java Objects to
Database Tables
● @Id and @Column(name="USERNAME") annotations
can be used on field levels.
● @PersistenceContext has to be used on EntityManager
JDBC and JDBCTemplate
● JDBC stands for Java Database Connectivity
● It is an application programming interface API for
connecting different databases
● Spring MVC uses jdbcTemplate in order to run queries
on databases
● JdbcTemplate simplifies database access code
● JdbcTemplate handles database related exceptions and
throws DataAccessException
PDF and Excel Documents
● In order to return PDF and Excel Documents
org.springframework.web.servlet.view.XmlViewResolver
has to be configured in Spring MVC Framework
● Documents have to extend related classes named as
AbstractExcelView and AbstractPdfView
● Apache POI is used to generate PDFs inside sample
applicaions
● Itext library is used to generate Excel documents
Spring MVC Java Config
● In order to configure Spring MVC with JavaConfig;
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = {"spring.javaconfig"})
public class JavaConfig extends WebMvcConfigurerAdapter {
● You don't need web.xml file with the new specification
Servlet API 3.0+
public class WebInitializer implements
WebApplicationInitializer {
@Override
public void onStartup(ServletContext servletContext)
throws ServletException {
Spring MVC Email
● Spring MVC can send emails to users using Java Mail
API
● Inside the sample application Velocity Email Template is
used in order to send customized emails
● Velocity is configured in configuration files and template
locations should be set
<!-- Velocity Email Template Config Bean -->
<bean id="velocityEngine"
class="org.springframework.ui.velocity.VelocityEngineFactoryBean">
<property name="resourceLoaderPath" value="/WEB-INF/email-templates/"/>
</bean>
Spring Security
● In order to activate Spring Security in Spring
MVC applications, springSecurityFilterChain has
to be configured in web.xml file with
DelegatingFilterProxy
● Spring Security annotations and custom tags
can be used in order to define java method level
security
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-
class>
</filter>
Spring Exception Handling
● Inside Spring MVC, users can define a exception
handling class by implementing
@Component
public class ExceptionHandler implements HandlerExceptionResolver{
private static final Logger logger =
LoggerFactory.getLogger(ExceptionHandler.class);
@Override
public ModelAndView resolveException(HttpServletRequest
request,HttpServletResponse response, Object object, Exception
exception) {
logger.error("Error: ", exception);
return new
ModelAndView("error/exception","exception","ExceptionHandler
message: " + exception.toString());
}
Spring REST with RestTemplate
● @RestController will add @ResponseBody annotations
to all methods inside a class
● RestTemplate is used to access Rest Based Web
Services
● @PathVariable is used in order to get variables from
URL
● ResponseEntity class is used to map response to Java
Objects
Enroll now to my udemy course
Tuna Tore
https://www.udemy.com/java-spring-mvc-framework-with-angularjs-by-google-and-html5

More Related Content

What's hot (20)

ODP
Spring Portlet MVC
John Lewis
 
PPTX
Spring MVC Architecture Tutorial
Java Success Point
 
PPT
Spring MVC
yuvalb
 
PDF
Spring MVC 3.0 Framework (sesson_2)
Ravi Kant Soni ([email protected])
 
PPTX
Java Server Faces + Spring MVC Framework
Guo Albert
 
PDF
Introduction to Spring MVC
Richard Paul
 
PDF
SpringMVC
Akio Katayama
 
PDF
Jsf intro
vantinhkhuc
 
PDF
Spring MVC
Aaron Schram
 
PPT
Struts Introduction Course
guest764934
 
ODP
A Complete Tour of JSF 2
Jim Driscoll
 
PDF
Spring Framework - MVC
Dzmitry Naskou
 
KEY
MVC on the server and on the client
Sebastiano Armeli
 
PDF
Spring mvc
Hamid Ghorbani
 
PPTX
Integration of Backbone.js with Spring 3.1
Michał Orman
 
PPT
Spring Core
Pushan Bhattacharya
 
PPT
JSF Component Behaviors
Andy Schwartz
 
ODP
Annotation-Based Spring Portlet MVC
John Lewis
 
PPTX
Spring framework in depth
Vinay Kumar
 
PPT
Jsf2.0 -4
Vinay Kumar
 
Spring Portlet MVC
John Lewis
 
Spring MVC Architecture Tutorial
Java Success Point
 
Spring MVC
yuvalb
 
Spring MVC 3.0 Framework (sesson_2)
Ravi Kant Soni ([email protected])
 
Java Server Faces + Spring MVC Framework
Guo Albert
 
Introduction to Spring MVC
Richard Paul
 
SpringMVC
Akio Katayama
 
Jsf intro
vantinhkhuc
 
Spring MVC
Aaron Schram
 
Struts Introduction Course
guest764934
 
A Complete Tour of JSF 2
Jim Driscoll
 
Spring Framework - MVC
Dzmitry Naskou
 
MVC on the server and on the client
Sebastiano Armeli
 
Spring mvc
Hamid Ghorbani
 
Integration of Backbone.js with Spring 3.1
Michał Orman
 
Spring Core
Pushan Bhattacharya
 
JSF Component Behaviors
Andy Schwartz
 
Annotation-Based Spring Portlet MVC
John Lewis
 
Spring framework in depth
Vinay Kumar
 
Jsf2.0 -4
Vinay Kumar
 

Similar to Java Spring MVC Framework with AngularJS by Google and HTML5 (20)

PDF
quickguide-einnovator-7-spring-mvc
jorgesimao71
 
PPTX
Spring mvc
Pravin Pundge
 
PDF
Spring Framework-II
People Strategists
 
PDF
Toms introtospring mvc
Guo Albert
 
PPTX
Spring MVC framework features and concepts
AsmaShaikh478737
 
PDF
Spring tutorial
Sanjoy Kumer Deb
 
PPT
Module 5.ppt.............................
Betty333100
 
PPTX
Spring Framework
tola99
 
PDF
Spring MVC introduction HVA
Peter Maas
 
PPTX
Spring mvc
nagarajupatangay
 
PPTX
Spring MVC 5 & Hibernate 5 Integration
Majurageerthan Arumugathasan
 
PPTX
Spring Web Presentation 123143242341234234
horiadobrin
 
ODP
Spring Mvc,Java, Spring
ifnu bima
 
PDF
Spring 2
Aruvi Thottlan
 
PDF
Spring MVC Framework
Hùng Nguyễn Huy
 
PDF
Spring mvc 2.0
Rudra Garnaik, PMI-ACP®
 
PDF
Multi Client Development with Spring - Josh Long
jaxconf
 
PPT
Spring Framework
nomykk
 
KEY
Multi Client Development with Spring
Joshua Long
 
PPTX
Spring tutorials
TIB Academy
 
quickguide-einnovator-7-spring-mvc
jorgesimao71
 
Spring mvc
Pravin Pundge
 
Spring Framework-II
People Strategists
 
Toms introtospring mvc
Guo Albert
 
Spring MVC framework features and concepts
AsmaShaikh478737
 
Spring tutorial
Sanjoy Kumer Deb
 
Module 5.ppt.............................
Betty333100
 
Spring Framework
tola99
 
Spring MVC introduction HVA
Peter Maas
 
Spring mvc
nagarajupatangay
 
Spring MVC 5 & Hibernate 5 Integration
Majurageerthan Arumugathasan
 
Spring Web Presentation 123143242341234234
horiadobrin
 
Spring Mvc,Java, Spring
ifnu bima
 
Spring 2
Aruvi Thottlan
 
Spring MVC Framework
Hùng Nguyễn Huy
 
Spring mvc 2.0
Rudra Garnaik, PMI-ACP®
 
Multi Client Development with Spring - Josh Long
jaxconf
 
Spring Framework
nomykk
 
Multi Client Development with Spring
Joshua Long
 
Spring tutorials
TIB Academy
 
Ad

Recently uploaded (20)

PPTX
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
PPTX
Nitrogen rule, ring rule, mc lafferty.pptx
nbisen2001
 
PDF
Is Assignment Help Legal in Australia_.pdf
thomas19williams83
 
PDF
AI-Powered-Visual-Storytelling-for-Nonprofits.pdf
TechSoup
 
PPTX
HUMAN RESOURCE MANAGEMENT: RECRUITMENT, SELECTION, PLACEMENT, DEPLOYMENT, TRA...
PRADEEP ABOTHU
 
PDF
Mahidol_Change_Agent_Note_2025-06-27-29_MUSEF
Tassanee Lerksuthirat
 
PDF
Vani - The Voice of Excellence - Jul 2025 issue
Savipriya Raghavendra
 
PPTX
How to Create Odoo JS Dialog_Popup in Odoo 18
Celine George
 
PPTX
EDUCATIONAL MEDIA/ TEACHING AUDIO VISUAL AIDS
Sonali Gupta
 
PPTX
Controller Request and Response in Odoo18
Celine George
 
PDF
Council of Chalcedon Re-Examined
Smiling Lungs
 
PDF
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
PPTX
DIGITAL CITIZENSHIP TOPIC TLE 8 MATATAG CURRICULUM
ROBERTAUGUSTINEFRANC
 
PPTX
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
PDF
IMPORTANT GUIDELINES FOR M.Sc.ZOOLOGY DISSERTATION
raviralanaresh2
 
PPTX
Light Reflection and Refraction- Activities - Class X Science
SONU ACADEMY
 
PDF
Introduction presentation of the patentbutler tool
MIPLM
 
PPTX
How to Configure Re-Ordering From Portal in Odoo 18 Website
Celine George
 
PDF
Week 2 - Irish Natural Heritage Powerpoint.pdf
swainealan
 
PDF
Governor Josh Stein letter to NC delegation of U.S. House
Mebane Rash
 
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
Nitrogen rule, ring rule, mc lafferty.pptx
nbisen2001
 
Is Assignment Help Legal in Australia_.pdf
thomas19williams83
 
AI-Powered-Visual-Storytelling-for-Nonprofits.pdf
TechSoup
 
HUMAN RESOURCE MANAGEMENT: RECRUITMENT, SELECTION, PLACEMENT, DEPLOYMENT, TRA...
PRADEEP ABOTHU
 
Mahidol_Change_Agent_Note_2025-06-27-29_MUSEF
Tassanee Lerksuthirat
 
Vani - The Voice of Excellence - Jul 2025 issue
Savipriya Raghavendra
 
How to Create Odoo JS Dialog_Popup in Odoo 18
Celine George
 
EDUCATIONAL MEDIA/ TEACHING AUDIO VISUAL AIDS
Sonali Gupta
 
Controller Request and Response in Odoo18
Celine George
 
Council of Chalcedon Re-Examined
Smiling Lungs
 
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
DIGITAL CITIZENSHIP TOPIC TLE 8 MATATAG CURRICULUM
ROBERTAUGUSTINEFRANC
 
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
IMPORTANT GUIDELINES FOR M.Sc.ZOOLOGY DISSERTATION
raviralanaresh2
 
Light Reflection and Refraction- Activities - Class X Science
SONU ACADEMY
 
Introduction presentation of the patentbutler tool
MIPLM
 
How to Configure Re-Ordering From Portal in Odoo 18 Website
Celine George
 
Week 2 - Irish Natural Heritage Powerpoint.pdf
swainealan
 
Governor Josh Stein letter to NC delegation of U.S. House
Mebane Rash
 
Ad

Java Spring MVC Framework with AngularJS by Google and HTML5

  • 1. Introduction to Spring MVC Framework Tuna Tore
  • 2. Enroll now to my udemy course Tuna Tore https://www.udemy.com/java-spring-mvc-framework-with-angularjs-by-google-and-html5
  • 3. What is MVC?  MVC stands for Model View Controller (architecture)  It is a design pattern used in WEB based JAVA Enterprise Applications  MVC pattern is also implemented in other WEB frameworks as well for separating the model layer from view layer. By doing that UI programmers and back end developers can work together.  Model Layer includes business specific logic  View Layer is responsible for rendering(displaying) model objects inside the user interface using different view technogies (JSP, Facelets or Velocity) (browser)  Controller receives user inputs and calls model objects based on handler mappings and pass model objects to views in order to display output inside the view layer.
  • 4. What is Dependency Injection?  This is also called as IOC (Inversion of Control Principle)  It is a software design pattern which is really useful for designing loosely coupled software components  You will have more plug-gable and testable code and objects  It is easy to reuse your code in other applications  The dependencies won't be hard coded inside all java objects/ classes instead they will be defined in XML configuration files or configuration classes (Java Config)  Spring Container is responsible for injecting dependencies of objects  There are two types of Dependency injection in Spring Framework Setter Injection and Constructor Injection
  • 6. The general information about web.xml and Java EE  The WEB-INF/web.xml is the Web Application Deployment Descriptor of Java Enterprise Web applications/  Inside web.xml, developers can define Servlets, Welcome File List Filters, Context parameters, Error pages Security rights and etc.
  • 7. The general information about the sample web application  Apache Maven Project  Pivotal tc server  Java Spring MVC 4.x version
  • 8. What is the concept of DispatcherServlet and how do you configure it?  DispatcherServlet is configured in order to dispatch incoming HTTP request to handlers and returns response to browsers  Spring MVC is designed around DispatcherServlet  DispatcherServlet is configured in web.xml file <servlet> <servlet-name>dispatcherServlet</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet- class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/classes/mvc-config.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>dispatcherServlet</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping>
  • 9. What is the concept of DispatcherServlet and how do you configure it?  DispatcherServlet is configured in order to dispatch incoming HTTP request to handlers and returns response to browsers  Spring MVC is designed around DispatcherServlet  DispatcherServlet is configured in web.xml file <servlet> <servlet-name>dispatcherServlet</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet- class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/classes/mvc-config.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>dispatcherServlet</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping>
  • 10. What is ContextLoaderListener and how do you configure it in Spring MVC?  ContextLoaderListener is responsible for creating a root application context in Java Enterprise Web application inside ServletContext  Developers can use different controller and view layers (For example Struts, JSF or Spring MVC can be used) however Spring Framework will be responsible for managing services layer or components defined ContextLoaderListener configuration files  You can set different configuration XML files in web.xml http://docs.spring.io/spring/docs/2.5.x/reference/mvc.html #mvc-servlet
  • 11. How do you configure controllers in Spring MVC?  By extending AbstractController class and implementing handleRequestInternal method  By using @Controller or @RestController annotation on class level  Controller with bean name URL mapping  Controller with class name mapping  Controller with XML config with mappings
  • 12. How is an incoming request mapped to a mapped to a method in Spring MVC?  @RequestMapping is used in order to map incoming request to a controller using URL matching  @RequestParam and @PathVariable is used to get parameters or variable from HTTP request @RequestMapping(value = "/jdbcDelete/user/{iduser}", method=RequestMethod.GET) public ModelAndView jdbcDelete(@PathVariable(value="iduser") int iduser) { @RequestMapping(value="/register", method=RequestMethod.POST) public ModelAndView register(@RequestParam(required=true) String email,@RequestParam(required=true) String password)
  • 13. What is a View in Spring MVC? How is the InternalResourceViewResolver configured?  Java Spring MVC can be configured with different view technologies such as Java Server Faces, JSP, Velocity etc.  Views are responsible for displaying the content of Model objects on browsers as response output  InternalResourceViewResolver is used to resolve the correct view based on suffix and prefixes so the correct output (view) is resolved based on strings
  • 14. Return types from Controllers You can return the followings from Controllers  ModelAndView  Model  Map  View  String  void  HttpHeaders and others
  • 15. Scopes in Spring MVC ● Default Scope in Spring MVC is request ● Session scope can be used in order to save the state of beans in web based applications ● Each time a request send through HTTP a new bean will be created with request scope
  • 16. Application Event Handling ● Developers can handle application events by implementing ApplicationListener<ApplicationEvent> ● Customs events can be published by using application context and extending ApplicationEvent class
  • 17. Spring MVC File Upload ● In order to upload a file with Java Spring MVC <!-- File Upload bean config--> <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartRe solver"> <!-- set the maximum file size in bytes --> <property name="maxUploadSize" value="1000000"/> </bean> @Controller public class FileUploadController { @RequestMapping(value="/uploadFile", method=RequestMethod.POST) public @ResponseBody String handleFileUpload(@RequestParam("file") MultipartFile file){
  • 18. Quartz Scheduling Framework and Spring Schedules  Quartz is an alternative to Spring Schedules and has more functionality  In order to use Quartz; Triggers, Jobs, Tasks and Scheduler have to defined in XML configuration  Spring Schedules can be configured using @Scheduled annotation  @Scheduled(cron="0/30 * * * * ?") or @Scheduled(fixedDelay = 10000) can be applied to schedules
  • 19. Logging in Spring MVC ● LOGBack framework will be used in order to log outputs ● LOGBack is a significantly improved version of log4j logging framework ● Both log4j and logback were founded with the same developer ● It is easy to switch logging technologies by using LOGBack ● The configuration is done through logback.xml ● By default Spring Framework use commons-logging so dependencies should be excluded in pom.xml
  • 20. Apache Maven ● Apache Maven is a build automation and dependency management tool ● Apache Maven is configured using pom.xml file ● Maven is integrated into Eclipse or STS
  • 21. JPA and Hibernate ORM ● JPA stands for Java Persistence API ● Hibernate ORM is an implementation of JPA ● ORM stands for Object Relational Mapping ● Hibernate ORM uses @Entity annotation to manage classes in ORM framework ● @Table(name="USER") is used to map Java Objects to Database Tables ● @Id and @Column(name="USERNAME") annotations can be used on field levels. ● @PersistenceContext has to be used on EntityManager
  • 22. JDBC and JDBCTemplate ● JDBC stands for Java Database Connectivity ● It is an application programming interface API for connecting different databases ● Spring MVC uses jdbcTemplate in order to run queries on databases ● JdbcTemplate simplifies database access code ● JdbcTemplate handles database related exceptions and throws DataAccessException
  • 23. PDF and Excel Documents ● In order to return PDF and Excel Documents org.springframework.web.servlet.view.XmlViewResolver has to be configured in Spring MVC Framework ● Documents have to extend related classes named as AbstractExcelView and AbstractPdfView ● Apache POI is used to generate PDFs inside sample applicaions ● Itext library is used to generate Excel documents
  • 24. Spring MVC Java Config ● In order to configure Spring MVC with JavaConfig; @Configuration @EnableWebMvc @ComponentScan(basePackages = {"spring.javaconfig"}) public class JavaConfig extends WebMvcConfigurerAdapter { ● You don't need web.xml file with the new specification Servlet API 3.0+ public class WebInitializer implements WebApplicationInitializer { @Override public void onStartup(ServletContext servletContext) throws ServletException {
  • 25. Spring MVC Email ● Spring MVC can send emails to users using Java Mail API ● Inside the sample application Velocity Email Template is used in order to send customized emails ● Velocity is configured in configuration files and template locations should be set <!-- Velocity Email Template Config Bean --> <bean id="velocityEngine" class="org.springframework.ui.velocity.VelocityEngineFactoryBean"> <property name="resourceLoaderPath" value="/WEB-INF/email-templates/"/> </bean>
  • 26. Spring Security ● In order to activate Spring Security in Spring MVC applications, springSecurityFilterChain has to be configured in web.xml file with DelegatingFilterProxy ● Spring Security annotations and custom tags can be used in order to define java method level security <filter> <filter-name>springSecurityFilterChain</filter-name> <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter- class> </filter>
  • 27. Spring Exception Handling ● Inside Spring MVC, users can define a exception handling class by implementing @Component public class ExceptionHandler implements HandlerExceptionResolver{ private static final Logger logger = LoggerFactory.getLogger(ExceptionHandler.class); @Override public ModelAndView resolveException(HttpServletRequest request,HttpServletResponse response, Object object, Exception exception) { logger.error("Error: ", exception); return new ModelAndView("error/exception","exception","ExceptionHandler message: " + exception.toString()); }
  • 28. Spring REST with RestTemplate ● @RestController will add @ResponseBody annotations to all methods inside a class ● RestTemplate is used to access Rest Based Web Services ● @PathVariable is used in order to get variables from URL ● ResponseEntity class is used to map response to Java Objects
  • 29. Enroll now to my udemy course Tuna Tore https://www.udemy.com/java-spring-mvc-framework-with-angularjs-by-google-and-html5