Introduction+to+Spring+Boot
Introduction+to+Spring+Boot
Spring in a Nutshell
The Problem
▸ Java Spring Boot (Spring Boot) is a tool that makes developing web application
and microservices with Spring Framework faster and easier through three core
capabilities:
Autoconfiguration
http://start.spring.io
10
mycode
mycode
Tomcat
Name of our JAR file
12
Spring Spring
Spring…
Core AOP
13
Q: Does Spring Boot run code faster than regular Spring code?
▸ No.
▸ • Behind the scenes, Spring Boot uses same code of Spring Framework
▸ Remember, Spring Boot is about making it easier to get started
▸ Minimizing configuration etc …
14
▸ No.
▸ You can use any IDE for Spring Boot apps … even use plain text editor
▸ The Spring team provides free Spring Tool Suite (STS) [IDE plugins]
▸ Some IDEs provide fancy Spring tooling support
▸ Not a requirement. Feel free to use the IDE that work s best for you
15
▸ Presentation Layer: The presentation layer handles the HTTP requests, translates
the JSON parameter to object, and authenticates the request and transfer it to the
business layer. In short, it consists of views i.e., frontend part.
▸ Business Layer: The business layer handles all the business logic. It consists of
service classes and uses services provided by data access layers. It also performs
authorization and validation.
▸ Persistence Layer: The persistence layer contains all the storage logic and
translates business objects from and to database rows
▸ Database Layer: In the database layer, CRUD (create, retrieve, update, delete)
operations are performed.
17
Spring Initializr
▸ When building your Java project, you may need additional JAR files
• For example: Spring, Hibernate, Commons Logging, JSON etc…
▸ One approach is to download the JAR files from each project web site
▸ Manually add the JAR files to your build path / classpath
21
Development Process
▸ Spring Boot provides a number of starters that allow us to add jars in the
classpath. Spring Boot built-in starters make development easier and rapid.
Spring Boot Starters are the dependency descriptors.
▸ We will explore this statement in detail with one example. For instance, we
would like to develop a Spring WebApplication with Tomcat WebServer.
▸ Then we need to add the following minimal jar dependencies in your Maven’s
pom.xml file or Gradle’s build.gradle file
▹ Metrics
▹ Audit
27
▸ Endpoint: The actuator endpoints allows us to monitor and interact with the
application. Spring Boot provides a number of built-in endpoints. We can also
create our own endpoint.
▸ Audit: Spring Boot provides a flexible audit framework that publishes events
to an AuditEventRepository. It automatically publishes the authentication
events if spring-security is in execution.
28
1. @SpringBootApplication Annotation
▸ This annotation is used to mark the main class of a Spring Boot application. It
encapsulates @SpringBootConfiguration, @EnableAutoConfiguration,and
2. @SpringBootConfiguration Annotation
▸ It is a class-level annotation that is part of the Spring Boot framework. It implies that a class
provides Spring Boot application configuration.
▸ It can be used as an alternative to Spring’s standard @Configuration annotation so that
configuration can be found automatically.
▸ Most Spring Boot Applications use @SpringBootConfiguration via SpringBootApplication. If
an application uses @SpringBootApplication, it is already using @SpringBootConfiguration.
33
3. @EnableAutoConfiguration Annotation
▸ @EnableAutoConfiguration: It auto-configures the bean that is present in the classpath and
configures it to run the methods. The use of this annotation is reduced in Spring Boot 1.2.0
release because developers provided an alternative of the annotation, i.e.
@SpringBootApplication.
34
4. @ComponentScan Annotation
▸ @ComponentScan tells Spring in which packages you have annotated classes that should
be managed by Spring
35
5. @ConditionalOnClass Annotation and
@ConditionalOnMissingClass Annotation
▸ @ConditionalOnClass Annotation used to mark auto-configuration bean if the class in the
annotation’s argument is present/absent.
36
6. @ConditionalOnBean Annotation and
@ConditionalOnMissingBean Annotation
▸ These annotations are used to let a bean be included based on the presence or absence of
specific beans.
37
7. @ConditionalOnProperty Annotation
▸ These annotations are used to let configuration be included based on the presence and
value of a Spring Environment property.
38
8. @ConditionalOnResource Annotation
▸ These annotations are used to let configuration be included only when a specific resource is
present in the classpath.
39
9. @ConditionalOnExpression Annotation
▸ These annotations are used to let configuration be included based on the result of a SpEL
(Spring Expression Language)
▸ SpEL (Spring Expression Language): It is a powerful expression language that supports
querying and manipulating an object graph at runtime.
40
THANKS!