SlideShare a Scribd company logo
1 of 15
Download to read offline
Spring Framework internals:

Beans and Initialization
Sidlyarevich Vlad
1
Father of Spring - Rod Johnson
• “Expert One-on-One J2EE Design
Development” Author
• Spring Source co-founder
• Nature lover
• PhD of Musicology
2
Version history
• The first version of the Spring framework was written by Rod Johnson along with a book in 2002. 

• The framework was first released in June 2003 under the Apache license version 2.0. 

• The first milestone release of Spring framework (1.0) was released in March 2004. 

• Spring 2.0, which came in 2006, simplified the XML config files.

• Spring 2.5, which came in 2007, introduced annotation configurations.

• Spring 3.2, which came in 2012, introduced Java configuration, had support for Java 7, Hibernate 4, Servlet 3.0, and also
required a minimum of Java 1.5. 

• Spring 4.0, which came in 2014, had support for Java 8. 

• Spring Boot also was introduced in 2014.

• Spring 5.0 came out in 2017. Spring Boot 2.x has support for Spring 5.
3
XML
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://
www.springframework.org/schema/beans/spring-beans.xsd">
<bean class="xml.init.services.ConsoleHelloService" scope="prototype">
<property name="message" value="dear"/>
<property name="nameService" ref="hardcodedNameService"/>
</bean>
<bean class="xml.init.services.HardcodedNameService" name="hardcodedNameService"
init-method="init"/>
</beans>
4
Annotation-based
@Service
@Scope(SCOPE_PROTOTYPE)
public class HardcodedNameService implements NameService {
@Override
public String getName() {
return "Jack";
}
@PostConstruct
public void init() {
}
}
5
Java configuration
@Configuration
public class MyConfiguration {
@Bean
public HelloService helloService() {
return new ConsoleHelloService();
}
}
6
BeanDefinition
• Java class full name (with packages)
• The unique identifier (if exists)
• Configs (init method, bean scope etc)
• Constructor args
• Setter args
7
BeanFactoryPostProcessor (BFPP)
• Transformations to groups of BeanDefinitions, before
any objects will be created
• Useful implementations are provided by framework
• Contains single method:
void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
throws BeansException;
8
FactoryBean
•Old way, used before Java Config
•BeanFactory can deal with it
public interface FactoryBean<T> {
T getObject() throws Exception;
Class<?> getObjectType();
boolean isSingleton();
}
9
Proxy pattern
10
BeanPostProcessor (BPP)
• Spring-managed too
• Can configure created beans
• Two useful methods:
Object postProcessBeforeInitialization(Object bean, String beanName) throws
BeansException;
Object postProcessAfterInitialization(Object bean, String beanName) throws
BeansException;
11
Multi-staged constructor
• Java constructor
• @PostConstruct (or init)
• On ContextRefreshedEvent
12
BeanPostProcessor (BPP)
• CommonAnnotationBeanPostProcessor - JSR-250
support (@PostConstruct etc)
• RequiredAnnotationBeanPostProcessor
• AutowiredAnnotationBeanPostProcessor
• ConfigurationClassPostProcessor
• PersistenceExceptionTranslationPostProcessor
13
Q & A
14
Thanks for attention!
15

More Related Content

Similar to Spring internals

Spring 4-groovy
Spring 4-groovySpring 4-groovy
Spring 4-groovy
GR8Conf
 
Spring framework
Spring frameworkSpring framework
Spring framework
Ajit Koti
 

Similar to Spring internals (20)

Spring 4-groovy
Spring 4-groovySpring 4-groovy
Spring 4-groovy
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
 
Spring MVC 5 & Hibernate 5 Integration
Spring MVC 5 & Hibernate 5 IntegrationSpring MVC 5 & Hibernate 5 Integration
Spring MVC 5 & Hibernate 5 Integration
 
Spring RestFul Web Services - CRUD Operations Example
Spring RestFul Web Services - CRUD Operations ExampleSpring RestFul Web Services - CRUD Operations Example
Spring RestFul Web Services - CRUD Operations Example
 
Mavenppt
MavenpptMavenppt
Mavenppt
 
Spring Boot and JHipster
Spring Boot and JHipsterSpring Boot and JHipster
Spring Boot and JHipster
 
Microservices with a Spark
Microservices with a SparkMicroservices with a Spark
Microservices with a Spark
 
Spring 3.1 in a Nutshell - JAX London 2011
Spring 3.1 in a Nutshell - JAX London 2011Spring 3.1 in a Nutshell - JAX London 2011
Spring 3.1 in a Nutshell - JAX London 2011
 
Spring Day | Spring 3.1 in a Nutshell | Sam Brannen
Spring Day | Spring 3.1 in a Nutshell | Sam BrannenSpring Day | Spring 3.1 in a Nutshell | Sam Brannen
Spring Day | Spring 3.1 in a Nutshell | Sam Brannen
 
JSF2
JSF2JSF2
JSF2
 
Hands On with Maven
Hands On with MavenHands On with Maven
Hands On with Maven
 
Apache maven
Apache mavenApache maven
Apache maven
 
Write code that writes code!
Write code that writes code!Write code that writes code!
Write code that writes code!
 
Write code that writes code! A beginner's guide to Annotation Processing - Ja...
Write code that writes code! A beginner's guide to Annotation Processing - Ja...Write code that writes code! A beginner's guide to Annotation Processing - Ja...
Write code that writes code! A beginner's guide to Annotation Processing - Ja...
 
Spring framework
Spring frameworkSpring framework
Spring framework
 
Spring 3.1: a Walking Tour
Spring 3.1: a Walking TourSpring 3.1: a Walking Tour
Spring 3.1: a Walking Tour
 
Sel study notes
Sel study notesSel study notes
Sel study notes
 
Jersey and JAX-RS
Jersey and JAX-RSJersey and JAX-RS
Jersey and JAX-RS
 
Spring data jpa are used to develop spring applications
Spring data jpa are used to develop spring applicationsSpring data jpa are used to develop spring applications
Spring data jpa are used to develop spring applications
 

Recently uploaded

Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...
Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...
Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...
drm1699
 

Recently uploaded (20)

Weeding your micro service landscape.pdf
Weeding your micro service landscape.pdfWeeding your micro service landscape.pdf
Weeding your micro service landscape.pdf
 
Abortion Clinic In Johannesburg ](+27832195400*)[ 🏥 Safe Abortion Pills in Jo...
Abortion Clinic In Johannesburg ](+27832195400*)[ 🏥 Safe Abortion Pills in Jo...Abortion Clinic In Johannesburg ](+27832195400*)[ 🏥 Safe Abortion Pills in Jo...
Abortion Clinic In Johannesburg ](+27832195400*)[ 🏥 Safe Abortion Pills in Jo...
 
Test Automation Design Patterns_ A Comprehensive Guide.pdf
Test Automation Design Patterns_ A Comprehensive Guide.pdfTest Automation Design Patterns_ A Comprehensive Guide.pdf
Test Automation Design Patterns_ A Comprehensive Guide.pdf
 
Abortion Clinic In Pongola ](+27832195400*)[ 🏥 Safe Abortion Pills In Pongola...
Abortion Clinic In Pongola ](+27832195400*)[ 🏥 Safe Abortion Pills In Pongola...Abortion Clinic In Pongola ](+27832195400*)[ 🏥 Safe Abortion Pills In Pongola...
Abortion Clinic In Pongola ](+27832195400*)[ 🏥 Safe Abortion Pills In Pongola...
 
Abortion Pill Prices Germiston ](+27832195400*)[ 🏥 Women's Abortion Clinic in...
Abortion Pill Prices Germiston ](+27832195400*)[ 🏥 Women's Abortion Clinic in...Abortion Pill Prices Germiston ](+27832195400*)[ 🏥 Women's Abortion Clinic in...
Abortion Pill Prices Germiston ](+27832195400*)[ 🏥 Women's Abortion Clinic in...
 
Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024
Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024
Anypoint Code Builder - Munich MuleSoft Meetup - 16th May 2024
 
Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...
Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...
Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...
 
Community is Just as Important as Code by Andrea Goulet
Community is Just as Important as Code by Andrea GouletCommunity is Just as Important as Code by Andrea Goulet
Community is Just as Important as Code by Andrea Goulet
 
Abortion Clinic Pretoria ](+27832195400*)[ Abortion Clinic Near Me ● Abortion...
Abortion Clinic Pretoria ](+27832195400*)[ Abortion Clinic Near Me ● Abortion...Abortion Clinic Pretoria ](+27832195400*)[ Abortion Clinic Near Me ● Abortion...
Abortion Clinic Pretoria ](+27832195400*)[ Abortion Clinic Near Me ● Abortion...
 
Abortion Clinic In Pretoria ](+27832195400*)[ 🏥 Safe Abortion Pills in Pretor...
Abortion Clinic In Pretoria ](+27832195400*)[ 🏥 Safe Abortion Pills in Pretor...Abortion Clinic In Pretoria ](+27832195400*)[ 🏥 Safe Abortion Pills in Pretor...
Abortion Clinic In Pretoria ](+27832195400*)[ 🏥 Safe Abortion Pills in Pretor...
 
Abortion Pill Prices Jane Furse ](+27832195400*)[ 🏥 Women's Abortion Clinic i...
Abortion Pill Prices Jane Furse ](+27832195400*)[ 🏥 Women's Abortion Clinic i...Abortion Pill Prices Jane Furse ](+27832195400*)[ 🏥 Women's Abortion Clinic i...
Abortion Pill Prices Jane Furse ](+27832195400*)[ 🏥 Women's Abortion Clinic i...
 
Workshop - Architecting Innovative Graph Applications- GraphSummit Milan
Workshop -  Architecting Innovative Graph Applications- GraphSummit MilanWorkshop -  Architecting Innovative Graph Applications- GraphSummit Milan
Workshop - Architecting Innovative Graph Applications- GraphSummit Milan
 
Lessons Learned from Building a Serverless Notifications System.pdf
Lessons Learned from Building a Serverless Notifications System.pdfLessons Learned from Building a Serverless Notifications System.pdf
Lessons Learned from Building a Serverless Notifications System.pdf
 
AzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdf
AzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdfAzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdf
AzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdf
 
BusinessGPT - Security and Governance for Generative AI
BusinessGPT  - Security and Governance for Generative AIBusinessGPT  - Security and Governance for Generative AI
BusinessGPT - Security and Governance for Generative AI
 
Transformer Neural Network Use Cases with Links
Transformer Neural Network Use Cases with LinksTransformer Neural Network Use Cases with Links
Transformer Neural Network Use Cases with Links
 
Modern binary build systems - PyCon 2024
Modern binary build systems - PyCon 2024Modern binary build systems - PyCon 2024
Modern binary build systems - PyCon 2024
 
Abortion Pill Prices Turfloop ](+27832195400*)[ 🏥 Women's Abortion Clinic in ...
Abortion Pill Prices Turfloop ](+27832195400*)[ 🏥 Women's Abortion Clinic in ...Abortion Pill Prices Turfloop ](+27832195400*)[ 🏥 Women's Abortion Clinic in ...
Abortion Pill Prices Turfloop ](+27832195400*)[ 🏥 Women's Abortion Clinic in ...
 
Evolving Data Governance for the Real-time Streaming and AI Era
Evolving Data Governance for the Real-time Streaming and AI EraEvolving Data Governance for the Real-time Streaming and AI Era
Evolving Data Governance for the Real-time Streaming and AI Era
 
[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse
[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse
[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse
 

Spring internals

  • 1. Spring Framework internals:
 Beans and Initialization Sidlyarevich Vlad 1
  • 2. Father of Spring - Rod Johnson • “Expert One-on-One J2EE Design Development” Author • Spring Source co-founder • Nature lover • PhD of Musicology 2
  • 3. Version history • The first version of the Spring framework was written by Rod Johnson along with a book in 2002. 
 • The framework was first released in June 2003 under the Apache license version 2.0. 
 • The first milestone release of Spring framework (1.0) was released in March 2004. 
 • Spring 2.0, which came in 2006, simplified the XML config files.
 • Spring 2.5, which came in 2007, introduced annotation configurations.
 • Spring 3.2, which came in 2012, introduced Java configuration, had support for Java 7, Hibernate 4, Servlet 3.0, and also required a minimum of Java 1.5. 
 • Spring 4.0, which came in 2014, had support for Java 8. 
 • Spring Boot also was introduced in 2014.
 • Spring 5.0 came out in 2017. Spring Boot 2.x has support for Spring 5. 3
  • 4. XML <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http:// www.springframework.org/schema/beans/spring-beans.xsd"> <bean class="xml.init.services.ConsoleHelloService" scope="prototype"> <property name="message" value="dear"/> <property name="nameService" ref="hardcodedNameService"/> </bean> <bean class="xml.init.services.HardcodedNameService" name="hardcodedNameService" init-method="init"/> </beans> 4
  • 5. Annotation-based @Service @Scope(SCOPE_PROTOTYPE) public class HardcodedNameService implements NameService { @Override public String getName() { return "Jack"; } @PostConstruct public void init() { } } 5
  • 6. Java configuration @Configuration public class MyConfiguration { @Bean public HelloService helloService() { return new ConsoleHelloService(); } } 6
  • 7. BeanDefinition • Java class full name (with packages) • The unique identifier (if exists) • Configs (init method, bean scope etc) • Constructor args • Setter args 7
  • 8. BeanFactoryPostProcessor (BFPP) • Transformations to groups of BeanDefinitions, before any objects will be created • Useful implementations are provided by framework • Contains single method: void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException; 8
  • 9. FactoryBean •Old way, used before Java Config •BeanFactory can deal with it public interface FactoryBean<T> { T getObject() throws Exception; Class<?> getObjectType(); boolean isSingleton(); } 9
  • 11. BeanPostProcessor (BPP) • Spring-managed too • Can configure created beans • Two useful methods: Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException; Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException; 11
  • 12. Multi-staged constructor • Java constructor • @PostConstruct (or init) • On ContextRefreshedEvent 12
  • 13. BeanPostProcessor (BPP) • CommonAnnotationBeanPostProcessor - JSR-250 support (@PostConstruct etc) • RequiredAnnotationBeanPostProcessor • AutowiredAnnotationBeanPostProcessor • ConfigurationClassPostProcessor • PersistenceExceptionTranslationPostProcessor 13