The document discusses Spring framework concepts including inversion of control (IOC), dependency injection, Spring modules, the IOC container, and configuring beans through XML. It provides examples of injecting properties, constructor arguments, inner beans, and aliases in the Spring XML configuration file. The examples demonstrate how Spring's IOC container instantiates, configures and wires Java objects defined as beans in the configuration.
1. Reach me @ :
Mallikarjuna G D
gdmallikarjuna@gmail.com
SNIPE TECH PVT LTD BANGALORE
2. INVERSION OF CONTROL (IOC) AND DEPENDENCY INJECTION
ADVANTAGES OF SPRING FRAMEWORK
SPRING MODULES
IOC CONTAINER
SPRING AOP
SPRING JDBCTEMPLATE
SPRING WITH ORM FRAMEWORKS
HIBERNATE AND SPRING INTEGRATION
SPRING MVC
2
CONTENTS
4/6/2022
6. 6
4/6/2022
INTRODUCTION
• Frameworks are has many inbuilt objects and this will be utilized and our own
objects solve the problems of realtime
• Frameworks usually developed by organization or experience software
professional to reduce the complexity of addressing the business automation
support packages
• The key advantages of framework are efficient, structured and secured
• The key challenges are binded framework guidelines and support dependency
• Examples :Angular, Reactjs, Django, Struts , Spring
7. Spring Framework
It was developed by Rod Johnson in 2003
Spring framework makes the easy development of JavaEE application.
Spring is a lightweight framework.
It can be thought of as a framework of frameworks because it provides
support to various frameworks
7
INTRODUCTION
4/6/2022
8. • Lightweight
• Flexible
• Loose coupling
• Declarative support
• Portable
• Well addressed cross cutting concerns
• Well structured configurations
• Life cycles
• Fast
• Secure
• Productivity
8
4/6/2022
10. Spring Core Container: The Spring Core container contains core, beans, context and expression
language (EL) modules. It is base module of spring (Bean factory and Application context)
AOP, Aspects and Instrumentation: The aspects module provides support to integration with
AspectJ. Enables cross cutting concerns
Core and Beans: These modules provide IOC and Dependency Injection features to mange life
cycle of java objects
Context: This module supports internationalization (I18N), EJB, JMS, Basic Remoting.
Expression Language: It provides support to setting and getting property values, method
invocation, accessing collections and indexers, named variables, logical and arithmetic operators,
retrieval of objects by name etc.
Test : This layer provides support of testing with JUnit and TestNG.
10
SPRING MODULES
4/6/2022
11. Data Access / Integration: This group comprises of JDBC, ORM, OXM, JMS and Transaction
modules. These modules basically provide support to interact with the database.
Web: This group comprises of Web, Web-Servlet, Web-Struts and Web-Portlet. These modules
provide support to create web application.
Transaction management: it standardized several transaction API’S to coordinates the
transactions over java objects
Messaging: Message queues or Java Messaging services and standardizes of message sender over
standard JMS API’s
11
SPRING MODULES
4/6/2022
12. package com.snipe.learning.springcore;
public class Employee {
public void displayInfo() {
System.out.println("Employee Information Display");
}
}
package com.snipe.learning.springcore;
public class Student {
public void displayInfo() {
System.out.println("Student Information Display");
}
}
12
TRADITIONAL
4/6/2022
package com.snipe.learning.springcore.test;
import com.snipe.learning.springcore.Employee;
import com.snipe.learning.springcore.Student;
public class TestChallengeDI {
public static void main(String args[]) {
Employee employee = new Employee();
employee.displayInfo();
Student student = new Student();
student.displayInfo();
}
}
13. package com.snipe.learning.springcore;
package com.snipe.learning.springcore;
public interface IPerson {
public void displayInfo();
}
public class Employee {
public void displayInfo() {
System.out.println("Employee Information Display");
}
}
package com.snipe.learning.springcore;
public class Student {
public void displayInfo() {
System.out.println("Student Information Display");
}
}
13
TRADITIONAL-POLYMORPHISM
4/6/2022
package com.snipe.learning.springcore.test;
import com.snipe.learning.springcore.Employee;
import com.snipe.learning.springcore.IPerson;
import com.snipe.learning.springcore.Student;
public class TestChallengeDI {
public static void main(String args[]) {
//polymorphism improvisation
IPerson person = new Employee();
person.displayInfo();
person = new Student();
person.displayInfo();
}
}
14. package com.snipe.learning.springcore;
public interface IPerson {
public void displayInfo();
}
package com.snipe.learning.springcore;
public class Employee implements IPerson{
public void displayInfo() {
System.out.println("Employee Information Display");
}
}
package com.snipe.learning.springcore;
public class Student implements IPerson{
public void displayInfo() {
System.out.println("Student Information Display");
}
}
14
RETHINK IMPEMENTION
4/6/2022
package com.snipe.learning.springcore;
public class Display {
IPerson person;
public IPerson getPerson() {
return person;
}
public void setPerson(IPerson person) {
this.person = person;
}
public void displayInfo() {
this.person.displayInfo();
}
}
15. package com.snipe.learning.springcore.test;
import com.snipe.learning.springcore.Display;
import com.snipe.learning.springcore.Employee;
import com.snipe.learning.springcore.Student;
public class TestChallengeDI {
public static void main(String args[]) {
//External supply of objects on needed
//IOC should be developed inject object
// Delegate to the container to do this task
Display display = new Display(); //DELEGATE
display.setPerson(new Student()); //DELEGATE
display.displayInfo();
display = new Display();//DELEGATE
display.setPerson(new Employee());//DELEGATE
display.displayInfo();
}
}
15
DELEGATE OBJECT INIALIZATION ?
4/6/2022
• Tell spring and delegate you inject Display to
Employee and student
• Spring IOC should take care of appropriate
object initialization
• Spring should take care of POJO object
initialization
• Behaviour handled by our Java code should
directly invoke dispaly
16. 16
SPRING SETUP?
4/6/2022
• Download spring latest release distribution https://repo.spring.io/ui/native/release/org/springframework/spring/
• Add jars as library to the project
object
object
object
object
object
object
object
CONTAINER
object
object
object
JAVA BUSINESS OBJECTS
18. 18
IOC CONTAINER
4/6/2022
The IoC container is responsible to instantiate, configure and assemble
the objects. The IoC container gets informations from the XML file and
works accordingly.
The main tasks performed by IoC container are:
o to instantiate the application class
o to configure the object
o to assemble the dependencies between
the objects.
19. There are two types of IoC containers. They are:
1)BeanFactory 2)ApplicationContext
19
IOC CONTAINER
4/6/2022
20. Spring BeanFactory
BeanFactory is core to the Spring framework
– Lightweight container that loads bean
definitions and manages your beans.
– Configured declaratively using an XML file,
or files, that determine how beans can be referenced and wired together.
– Knows how to serve and manage a singleton or prototype defined bean
– Responsible for lifecycle methods.
– Injects dependencies into defined beans when served
20
IOC CONTAINER
4/6/2022
21. 21
Bean Example
<bean id="employee" class="com.snipe.learning.springcore.di.Employee" />
<bean id="student" class="com.snipe.learning.springcore.di.Student" />
The XmlBeanFactory is the implementation class for the BeanFactory interface.
The constructor of XmlBeanFactory class receives the Resource object
so we need to pass the resource object to create the object of BeanFactory.
Resource resource=new ClassPathResource("applicationContext.xml");
BeanFactory factory=new XmlBeanFactory(resource);
IOC CONTAINER
4/6/2022
22. 22
public class Employee implements IPerson {
private String cname;
public String getCname() {
return cname;
}
public void setCname(String cname) {
this.cname = cname;
}
public void displayInfo() {
System.out.println("Employee Company is:" + this.cname);
}
}
INJECT PROEPRTIES
4/6/2022
package com.snipe.learning.springcore.di;
public class Student implements IPerson{
private String cname;
public String getCname() {
return cname;
}
public void setCname(String cname) {
this.cname = cname;
}
public void displayInfo() {
System.out.println("Student college"+this.cname);
}
}
<!-- bean definitions here -->
<bean id="employee"
class="com.snipe.learning.springcore.di.Employee">
<property name="cname" value="SNIPE TECH PVT LTD"></property>
</bean>
<bean id="student"
class="com.snipe.learning.springcore.di.Student">
<property name="cname" value="J.N.N.C.E"></property>
</bean>
29. 29
autowire
4/6/2022
Autowiring is injecting object implicitly without external implementation. This
works matching by Name, Type or constructor arguments.
This works only for reference objects not for primitive or strings
Mode Description
no No autowiring default
byName The byName mode injects the based on the name. In this case property name and bean name must be same. It
internally calls setter method.
byType The byType mode injects based on type object. So property name and bean name can be different. It internally calls
setter method. It works only one bean exists.
constructor The constructor mode injects by calling the constructor of the class. It calls the constructor having large number of
parameters. It works only one bean of that class.
33. 33
scope
4/6/2022
The Spring scopes are tells how many instances of beans are available to use it.
By default only one bean instance will be created as and when context file loaded.
Scopes are
• Singleton – only one instance created during loading of context xml flile
• Prototype –it creates more than one instance as and when the getBean method
called. To each request the instance will be created.
• Web aware context in spring
• Request –spring on each servlet request bean will be created
• Session –New bean per session
• Global –session –New bean per one HTTP Request session(portlet context)
<bean id="employee" class="com.snipe.learning.springcore.di.Employee" autowire="byType" scope="prototype"></bean>
<bean id="homeAddress" class="com.snipe.learning.springcore.di.Address">
<property name="street" value="shatrugna marga" />
<property name="area" value="srirampura 2nd stage" />
<property name="city" value="mysuru" />
</bean>
ANNOTATION
@Bean
@Scope("prototype")
34. 34
ApplicationContextAware, BeanNameAware
4/6/2022
• BeanFactory instantiate bean when you call getBean() method
while ApplicationContext instantiate Singleton bean when container is started,
It doesn't wait for getBean() to be called.
• BeanFactory doesn't provide support for internationalization
but ApplicationContext provides support for it.
• Another difference between BeanFactory vs ApplicationContext is ability to
publish event to beans that are registered as listener.
• One of the popular implementation of BeanFactory interface
is XMLBeanFactory while one of the popular implementation
of ApplicationContext interface is ClassPathXmlApplicationContext.
• If you are using auto wiring and using BeanFactory than you need to
register AutoWiredBeanPostProcessor using API which you can configure in
XML if you are using ApplicationContext. In summary BeanFactory is OK for
testing and non production use but ApplicationContext is more feature rich
container implementation and should be favored over BeanFactory
35. 35
ApplicationContextAware, BeanNameAware
4/6/2022
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
public class Student implements ApplicationContextAware, BeanNameAware {
private ApplicationContext context = null;
public ApplicationContext getContext() {
return context;
}
@Override
public void setBeanName(String bean) {
// TODO Auto-generated method stub
System.out.println("bean name::" + bean);
}
@Override
public void setApplicationContext(ApplicationContext context) throws BeansException {
// TODO Auto-generated method stub
this.context = context;
}
}
36. 36
INHERITANCE
4/6/2022
public class Person {
protected String name;
protected int age;
protected String sex;
..
}
public class Student extends Person {
private String cname;
private String std;
private float Scholorship;
..
}
<bean id="person" class="com.snipe.learning.springcore.di.Person">
<property name="name" value="Pranet M D" />
<property name="age" value="13" />
<property name="sex" value="Male" />
</bean>
<bean id="student"
class="com.snipe.learning.springcore.di.Student" parent="person">
<property name="cname" value="J.N.N.C.E" />
<property name="std" value="MTech" />
<property name="scholorship" value="10000" />
</bean>
37. 37
LIFE CYCLE CALL BACK METHODS
4/6/2022
public class Student extends Person implements InitializingBean, DisposableBean {
@Override
public void destroy() throws Exception {
// TODO Auto-generated method stub
System.out.println("Destry bean"); }
public void afterPropertiesSet() throws Exception {
System.out.println("Initializing bean"); }
public void init_bean() {
System.out.println("Init method");
}
public void cleanup() {
System.out.println("cleanup method"); }
}
<bean id="person" class="com.snipe.learning.springcore.di.Person">
<property name="name" value="Pranet M D" />
<property name="age" value="13" />
<property name="sex" value="Male" />
</bean>
<bean id="student"
class="com.snipe.learning.springcore.di.Student" parent="person" init-method="init_bean" destroy-method="cleanup">
<property name="cname" value="J.N.N.C.E" />
<property name="std" value="MTech" />
<property name="scholorship" value="10000" />
</bean>
38. 38
INTERFACE USAGE
4/6/2022
package com.snipe.learning.springcore.di;
public interface IPerson {
public void displayInfo();
}
package com.snipe.learning.springcore.di;
public class Student implements IPerson {
@Override
public void displayInfo() {
System.out.println("STUDENT INFORMATION");
} }
package com.snipe.learning.springcore.di;
public class Employee implements IPerson{
@Override
public void displayInfo() {
System.out.println("EMPLOYEE INFORMATION");
}
}
<!-- bean definitions here -->
<!-- <bean id="person" class="com.snipe.learning.springcore.di.IPerson"/>
--><bean id="student" class="com.snipe.learning.springcore.di.Student" />
<bean id="employee" class="com.snipe.learning.springcore.di.Employee" />
</beans>
public class TestDIMAIN {
public static void main(String[] args) {
System.out.println("In CLASSPATH BEAN FACTORY");
AbstractApplicationContext context = new
ClassPathXmlApplicationContext("applicationContext.xml");
context.registerShutdownHook();
IPerson student = (Student)context.getBean("student");
student.displayInfo();
IPerson employee = (Employee)context.getBean("employee");
employee.displayInfo();
}
}
39. 39
SPRING AOP
4/6/2022
• Aspect-Oriented Programming (AOP)
complements Object-Oriented
Programming (OOP) by providing another
way of thinking about program structure.
• Aspects enable the modularization of
concerns such as transaction management
that cut across multiple types and objects.
(Such concerns are often
termed crosscutting concerns in AOP
literature.)
• Objects have other than business model
details like managing logging, transaction,
security so on
• This code required in all methods
• We cannot manage or modify at once.
40. Where use AOP
AOP is mostly used in following cases:
• to provide declarative enterprise services such
as declarative transaction management.
• It allows users to implement
custom aspects.
Steps of AOP
• Write Aspect
• Configure Aspect
40
SPRING AOP
4/6/2022
42. Core AOP concepts
Join point
An identifiable point in the execution of a program.
Central, distinguishing concept in AOP
Pointcut
Program construct that selects join points and collects context at
those points.
Advice
Code to be executed at a join point that has been selected by a
pointcut
Introduction
Additional data or method to existing types, implementing new
interfaces
42
SPRING AOP
4/6/2022
43. • Advice
• Advice represents an action taken by an aspect at a particular join point.
There are different types of advices:
• Before Advice: it executes before a join point.
• After Returning Advice: it executes after a joint point completes
normally.
• After Throwing Advice: it executes if method exits by throwing an
exception.
• After (finally) Advice: it executes after a join point regardless of join
point exit whether normally or exceptional return.
• Around Advice: It executes before and after a join point.
43
SPRING AOP
4/6/2022
44. Spring AOP AspectJ Annotation
• There are two ways to use Spring AOP AspectJ implementation:
• By annotation: We are going to learn it here.
• By xml configuration
(schema based)
44
SPRING AOP
4/6/2022
45. • Spring AspectJ AOP implementation provides many annotations:
• @Aspect
• @Pointcut:
The annotations used to create advices are given below:
• @Before
• @After
• @After Returning
• @Around
• @AfterThrowing
45
SPRING AOP
4/6/2022
46. Bean class
public class ExampleModel {
public void read() {
System.out.println("read info");
}
}
applicationContext.xml
<aop:aspectj-autoproxy/>
<bean id="exampleModel"
class="com.snipe.learning.aop.model.ExampleModel" />
<bean id="aspectWorkExample"
class="com.snipe.learning.aop.aspectservice.ExampleBeforeA
spect"/>
46
@BEFORE
4/6/2022
@Aspect
public class ExampleBeforeAspect {
@Before("allread()")
public void LoggingAdvice() {
System.out.println("Logging Advice");
}
@Pointcut("execution(public void read())")
public void allread() {}
}
Output:
Logging Advice
read info
47. Bean class
public class ExampleModel {
public void read() {
System.out.println("read info");
}
}
applicationContext.xml
<aop:aspectj-autoproxy/>
<bean id="exampleModel"
class="com.snipe.learning.aop.model.ExampleModel" />
<bean id="aspectWorkExample"
class="com.snipe.learning.aop.aspectservice.ExampleAfterAs
pect"/>
47
@AFTER
4/6/2022
@Aspect
public class ExampleAfterAspect {
@After("allread()")
public void LoggingAdvice() {
System.out.println("Logging Advice");
}
@Pointcut("execution(public void read())")
public void allread() {}
}
Output:
read info
Logging Advice
48. Bean class
public class ExampleModel {
public void read() {
System.out.println("read info");
//throw new RuntimeException();
}
}
applicationContext.xml
<aop:aspectj-autoproxy/>
<bean id="exampleModel"
class="com.snipe.learning.aop.model.ExampleModel" />
<bean id="aspectWorkExample"
class="com.snipe.learning.aop.aspectservice.ExampleAfterAs
pect"/>
48
@AFTERRETURNING
4/6/2022
@Aspect
public class ExampleAfterAspect {
@AfterReturning("allread()")
public void LoggingAdvice() {
System.out.println("Logging Advice");
}
@Pointcut("execution(public void read())")
public void allread() {}
}
Output:
read info
Logging Advice
49. Bean class
public class ExampleModel {
public void read() {
System.out.println("read info");
int nume = 10/0;
System.out.println(num); }
}
applicationContext.xml
<aop:aspectj-autoproxy/>
<bean id="exampleModel"
class="com.snipe.learning.aop.model.ExampleModel" />
<bean id="aspectWorkExample"
class="com.snipe.learning.aop.aspectservice.ExampleExceptio
nAspect"/>
49
@AFTERTHROWING
4/6/2022
@Aspect
public class ExampleExceptionAspect {
@AfterReturning("allread()")
public void ReturningAdvice() {
System.out.println("Returning Advice");
}
@AfterThrowing("allread()")
public void ExceptionAdvice() {
System.out.println("Exception Advice");
}
@Pointcut("execution(public void read())")
public void allread() {}
}
Output:
read info
Exception Advice
Exception in thread "main" java.lang.ArithmeticException: / by zero
50. Bean class
package com.snipe.learning.aop.model;
public class ExampleModel {
public String readInfo(String name) {
System.out.println("read info");
System.out.println(name);
return name;
}
}
applicationContext.xml
<aop:aspectj-autoproxy/>
<bean id="exampleModel"
class="com.snipe.learning.aop.model.ExampleModel" />
<bean id="aspectWorkExample"
class="com.snipe.learning.aop.aspectservice.
ExampleAfteReturningAspect"/>
50
@AFTERRETURNING
4/6/2022
@@Aspect
public class ExampleAfteReturningAspect {
@AfterReturning("args(name)")
public void LoggingAdvice(String name) {
System.out.println("Logging Advice"+name);
}
@Pointcut("execution(public void read())")
public void allread() {}
}
Output:
read info
mallikarjuna
Logging Advicemallikarjuna
51. Bean class
package com.snipe.learning.aop.model;
public class ExampleModel {
public void readInfo() {
System.out.println("read info");
}
}
applicationContext.xml
<aop:aspectj-autoproxy/>
<bean id="exampleModel"
class="com.snipe.learning.aop.model.ExampleModel" />
<bean id="aspectWorkExample"
class="com.snipe.learning.aop.aspectservice.ExampleAroundA
spect"/>
51
@AROUND
4/6/2022
@Around("allread()")
public void aroundAdvice(ProceedingJoinPoint proceedingJoinPoint) {
System.out.println("Logging Advice");
try {
System.out.println("before advice");
proceedingJoinPoint.proceed();
System.out.println("after advice");
}catch(Throwable te) {
System.out.println("After Throwing");
}
}
@Pointcut("execution(public void readInfo())")
public void allread() {}
Test ::
ApplicationContext context = new ClassPathXmlApplicationContext
("applicationContext.xml");
ExampleModel exampleModel =context.getBean
("exampleModel", ExampleModel.class);
exampleModel.readInfo();
Output:
Logging Advice
before advice
read info
after advice
53. Data Access Model:
Spring JdbcTemplate
Problems of JDBC API
The problems of JDBC API are as follows:
We need to write a lot of code before and after executing the query,
such as creating connection, statement, closing resultset, connection etc.
We need to perform exception handling code on the database logic.
Repetition of all these codes from one to another database logic is a
time consuming task.
53
Spring JdbcTemplate
4/6/2022
54. Advantage of Spring JdbcTemplate
• Spring JdbcTemplate eliminates all the above mentioned
problems of JDBC API. It provides you methods to write
the queries directly, so it saves a lot of
work and time.
54
Spring JdbcTemplate
4/6/2022
56. Spring Jdbc Approaches
Spring framework provides following approaches for JDBC database
access:
JdbcTemplate
NamedParameterJdbcTemplate
SimpleJdbcTemplate
SimpleJdbcInsert and SimpleJdbcCall
56
Spring JdbcTemplate
4/6/2022
57. Spring MVC
• In Spring Web MVC, DispatcherServlet class works as the front controller. It
is responsible to manage the flow of the spring mvc application.
4/6/2022 57
Spring MVC
58. Advantages of Spring 3.0 MVC
Supports RESTful URLs.
Annotation based configuration.
Supports to plug with other MVC frameworks like Struts etc.
Flexible in supporting different view types like JSP, velocity, XML,
PDF etc.,
4/6/2022 58
Spring MVC
59. Front Controller - Responsiblities
• Initialize the framework to cater to the requests.
• Load the map of all the URLs and the components
responsible to handle the request.
• Prepare the map for the views.
4/6/2022 59
Spring MVC
61. Spring Boot File Structure
Spring Boot Simple Example
SPRING BOOT IN ECLIPSE
4/6/2022
61
CONTENTS
62. • Spring Boot is a Framework from “The Spring Team” to ease the
bootstrapping and development of new Spring Applications.
4/6/2022 62
INTRODUCTION
• Spring Boot makes it easy to create stand-alone, production-grade
Spring based Applications that you can “just run”.
• We take an opinionated view of the Spring platform and third-party
libraries so you can get started with minimum fuss.
• Most Spring Boot applications need very little Spring configuration.
INTRODUCTION
63. What is Spring ?
4/6/2022 63
Application framework
Programming and Configuration model
Infrastructure support
Challenges
Looks like very vast framework
Lot more setup and configuration hudles
Lot more deployment modes
64. What is Spring Boot ?
• It is a Spring module which provides RAD (Rapid Application Development)
feature to Spring framework.
• It provides defaults for code and annotation configuration to quick start new
Spring projects within no time. It follows “Opinionated Defaults
Configuration” Approach to avoid lot of boilerplate code and configuration to
improve Development, Unit Test and Integration Test Process.
4/6/2022 64
SPRING BOOT
SPRING
FRAMEWORK
Embedded HHTP
Servers,
(Tomcat, Jetty)
XML <Bean>
Configuration
65. WHY USE SPRING BOOT?
• To ease the Java-based applications Development, Unit Test and
Integration Test Process and Time. To increase Productivity.
• To avoid XML Configuration completely.
• To avoid defining more Annotation Configuration(It combined some
existing Spring Framework Annotations to a simple and single
Annotation)
• To avoid writing lots of import statements
• To provide some defaults to quick start new projects within no time.
• To provide Opinionated Development approach.
4/6/2022 65
WHY USE SPRING BOOT?
66. • To Setup default configuration
• Starts a application context
• Problems of class path scan
• Starts tomcat server
4/6/2022 66
WHAT SPRING BOOT DOES
67. Spring
• Dependency Injection Framework
• Manage Lifecycle Of Java(Beans)
• Boiler plate configuration
-programmer writes a lot of code
to minimal task
• Takes Time to have a spring
application up and run
Spring Boot
• A suite of pre-configured
frameworks and technologies
-That is used to remove
boilerplate configuration
• The shortest way to have
application up and running
4/6/2022 67
68. Spring Boot Framework has mainly four major Components.
Spring Boot Starters: Spring Boot Starters is one of the major key features or
components of Spring Boot Framework. The main responsibility of Spring Boot Starter is to
combine a group of common or related dependencies into single dependencies.
Spring Boot Auto Configurator; AutoConfigurator is to reduce the Spring Configuration. If we
develop Spring applications in Spring Boot, then We don't need to define single XML configuration and
almost no or minimal Annotation configuration. Spring Boot Auto Configurator component will take care of
providing those information.
Spring Boot CLI: Spring Boot CLI(Command Line Interface) is a Spring Boot software to run and test
Spring Boot applications from command prompt. When we run Spring Boot applications using CLI, then it
internally uses Spring Boot Starter and Spring Boot AutoConfigurate components to resolve all
dependencies and execute the application.
4/6/2022 68
COMPONENTS OF SPRING BOOT
69. Spring Boot Starters: The spring-boot-actuator module provides all of Spring Boot’s production-
ready features. The recommended way to enable the features is to add a dependency on the spring-boot-
starter-actuator “Starter”.
4/6/2022 69
COMPONENTS OF SPRING BOOT
71. Its look like:
4/6/2022 71
EXAMPLES
• Spring Boot Starters:
example: if we want to get started using Spring and JPA for database access,
just include the spring-boot-starter-data-jpa dependency
Pattern: spring-boot-starter-*, where *
spring-boot-starter-web It is used for building web, including RESTful, applications
using Spring MVC. Uses Tomcat as the default embedded
container.
spring-boot-starter-jdbc It is used for JDBC with the Tomcat JDBC
connection pool.
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
COMPONENTS OF SPRING BOOT
72. 4/6/2022 72
• Spring Boot Auto Configurator
example; • Spring Boot Starter reduces build’s dependencies and Spring Boot
AutoConfigurator reduces the Spring Configuration.
• Spring Boot Starter has a dependency on Spring Boot
AutoConfigurator, Spring Boot Starter triggers Spring Boot
AutoConfigurator automatically.
@SpringBootAppliction @Configuration @ComponentScan @EnableAutoConfig
COMPONENTS OF SPRING BOOT
73. Spring Boot Starters: The spring-boot-actuator module provides all of Spring Boot’s production-
ready features. The recommended way to enable the features is to add a dependency on the spring-boot-
starter-actuator “Starter”.
4/6/2022 73
COMPONENTS OF SPRING BOOT
75. . Bill of Materials
version dependency management of all the dependent child jars
• Embedded Tomcat Server
– Manage the servlet container
– Standalone run
– Microservice architecture support
– Developer free from lot of configurations
4/6/2022 75
HIDDEN TREASURE
76. Post Man
4/6/2022 76
We will use this postman application for using
these services
• GET
• POST
• PUT
• DELETE
SPRING BOOT IN ECLIPSE
79. 4/6/2022 79
• See the website for common application.properites
spring application.properties
80. 1) What is Spring?
2) What are the advantages of spring framework?
3) What are the modules of spring framework?
4) What is IOC and DI?
5) What is the role of IOC container in spring?
6) What are the types of IOC container in spring?
7) What is the difference between BeanFactory and ApplicationContext?
8) What is the difference between constructor injection and setter injection?
9) What is autowiring in spring? What are the autowiring modes?
10) What are the different bean scopes in spring?
11) In which scenario, you will use singleton and prototype scope?
80
Spring Interview Questions
81. 12 What are the advantages of JdbcTemplate in spring?
13) What are the advantages of spring AOP?
14) What is interceptor?
15)Does spring perform weaving at compile time?
16) What are the AOP implementation?
17) What is the front controller class of Spring MVC?
18) What does @Controller annotation?
19) What does @RequestMapping annotation?
20) What does the ViewResolver class?
21) Which ViewResolver class is widely used?
22) Does spring MVC provide validation support? 81
Spring Interview Questions