Session 03 Spring Framework
Session 03 Spring Framework
ANTEA TRAINING
Spring Framework
Session 03
• Summary
• The Spring Framework overview
• Spring Boot
Session 02
• org.springframework.core-3.0.1.RELEASE-A
• com.springsource.org.apache.commons.logging-1.1.1
• org.springframework.beans-3.0.1.RELEASE-A
• ApplicationContext
• AOP
• message
• resource handling
Spring Framework
• Dependency Injection in Spring:
• Dependency Injection (DI) is a design pattern that removes
the dependency from the programming code so that it can be
easy to manage and test the application.
• Insuch case we provide the information from the external
source such as XML file.
• It makes our code loosely coupled and easier for testing.
• 1) no
• 2) byName
• 3) byType
• 4) constructor
• 5) autodetect (Deprecated)
Spring Framework
• Autowiring in Spring:
Spring Framework
• Autowiring in Spring:
• no autowiring mode
Session 02
This attribute is mandatory and specifies the bean class to be used to create the
class
bean
This attribute specifies the scope of the objects created from a particular bean
scope
definition.
lazy-initialization A lazy-initialized bean tells the IoC container to create a bean instance when it is
mode first requested, rather than at the startup.
A callback to be called just after all necessary properties on the bean have been
initialization method set by the container.
destruction method A callback to be used when the container containing the bean is destroyed.
Spring Framework
• Spring - Bean Scopes:
• The scope of a bean defines the life cycle and visibility of that
bean in the contexts we use it.
• The latest version of the Spring framework defines 6 types of
scopes:
• singleton
• prototype
Spring Boot
Session 03
Spring Boot
• Spring Boot introduction:
• Spring Boot is an open source Java-based framework used to
create a micro Service.
• Micro Service is an architecture that allows the developers to
develop and deploy services independently.
• Each service running has its own process and this achieves
the lightweight model to support business applications.
• Spring Boot provides a good platform for Java developers to
develop a stand-alone and production-grade spring
application based on micro services architecture.
Spring Boot
• Spring Boot introduction:
• Advantages :
• Easy to understand and develop spring applications
• Increases productivity
• Reduces the development time
• Goals:
• To avoid complex XML configuration in Spring
• To develop a production ready Spring applications in an easier
way
• To reduce the development time and run the application
independently
• Offer an easier way of getting started with the application
Spring Boot
• Why Spring Boot ?
• It
provides a flexible way to configure Java Beans, XML
configurations, and Database Transactions.
• It
provides a powerful batch processing and manages REST
endpoints.
• InSpring Boot, everything is auto configured; no manual
configurations are needed.
• It offers annotation-based spring application
• https://start.spring.io/
is a web-based tool provided by the
Pivotal Web Service. With the help of Spring Initializr, we can
easily generate the structure of the Spring Boot Project.
• It offers extensible API for creating JVM-based projects.
Spring Security
Session 03
Spring Security
• Spring Security Introduction:
• Spring Security is a framework which provides various
security features like: authentication, authorization to create
secure Java Enterprise Applications.
• Authorization is
the process to allow authority to perform
actions in the application. We can apply authorization to
authorize web request, methods and access to individual
domain.
• Thebeauty of this framework is its flexible authentication
nature to integrate with any software solution.
• HTTP BASIC, LDAP, OpenID, Kerberos, Oauth2 …
Spring Security
• Spring Security Advantages :
• Comprehensive support for authentication and authorization.
• Protection against common tasks
• Servlet API integration
• Integration with Spring MVC
• Portability
• CSRF protection
• Java Configuration support
Spring Security
• Spring Project Modules:
• spring-security-core.jar
• spring-security-remoting.jar
• spring-security-web.jar
• spring-security-config.jar
• spring-security-ldap.jar
• spring-security-oauth2-*.jar (JWT)
• spring-security-acl.jar (Security Access Control List)
• spring-security-cas.jar (Central Authentication Service, SSO)
• spring-security-openid.jar
• spring-security-test.jar
Spring Security
• Spring Security Project : Create Spring Security Java configuration
Spring Security
• SpringSecurity Project : register the springSecurityFilterChain
for every URL in our application.
• To register, Spring Security provides a base class
AbstractSecurityWebApplicationInitializer that we need to
extend.
Spring Security
• Spring Security Project : load WebSecurityConfig in our existing
ApplicationInitializer and add into the getRootConfigClasses()
method.
Spring Security
• Spring Security Project : WebSecurityConfigurerAdapter class
provides a configure(HttpSecurity http) method that contains
the following default configuration.
Spring Security
• SpringSecurity Project : Creating a controller to handle user
requests.
Spring Security
• Spring Security Project : Test our application.
Spring Security
• Spring Security Project : Test our application.
Session 03
Spring Test
• Spring Test Framework :