SlideShare une entreprise Scribd logo
1  sur  22
Spring
“Less” is More
Based on the official reference docs (v4.3.2)
What is it?
- Application framework
- Inversion of Control (IoC) container
- Dependency Injection (DI)
- “Ask the framework for the resource”
- Many additional (optional) modules
- AOP, Web MVC, Data, Security, Mobile, ...
- “Alternative” to Java EE
- Actually, on top and ahead of it
Why is it?..
- Historically, greatly eased application
development
- Java EE implementations has since caught up nicely
- Not held back by standardization committees
- Advanced features not yet in the Java EE spec
- No need for a full application server
- Servlet container is enough
- Highly modular and granular DI
Spring Projects
Spring Framework
Bootstrapping
- Configuration
- XML
- Java-based
- IoC container init
- ApplicationContext
- Wiring
- Run-time factory
Basic XML Configuration
<?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">
<import resource="helloOtherWorldConfig.xml"/>
<bean id="helloWorld" class="com.world.HelloWorld" scope="prototype" lazy-init="true">
<property name="param1" value="21"/>
<property name="param2" ref="helloOtherWorld"/>
</bean>
</beans>
Basic Java Configuration
Basic Usage
// create and configure beans - XML
ApplicationContext context =
new ClassPathXmlApplicationContext("helloWorldConfig.xml");
// create and configure beans - Java-based
ApplicationContext context =
new AnnotationConfigApplicationContext(HelloWorldConfig.class);
// retrieve configured instance
HelloWorld greeter = context.getBean("helloWorld", HelloWorld.class);
// use configured instance
String greeting = greeter.greet();
Naming
- Each bean must have a unique identifier
- If none provided in configuration - names are
camel-cased
- Derived similar to JSON convention:
- objectProperty -> objectProperty
- ObjectProperty -> objectProperty
- OBJECTPROPERTY -> oBJECTPROPERTY
Beans
- Essentially - POJO
- But works with convoluted hierarchies
- @Bean + @Configuration / @Component
- @Lazy
- @Scope
- singleton, prototype, request, session
- @Profile
- …, …, …
Beans Wiring
- @Autowired
- Inferred
- Can be advised
- Constructor-based DI for mandatory
dependencies
- Usually - prefer this method
- Setter-based DI for optional dependencies
- Useful for cases of circular dependencies
AOP
- Crosscutting concerns
- Spring, logging, security, etc.
- @Aspect
- @Pointcut(“...”)
- E.g.: "execution (* com.company.*.*(..))
- JoinPoint
- @Before
- @After, @AfterReturning, @AfterThrowing
- @Around
MVC
- Model
- @Repository
- View
- @Controller + @ResponseBody
- @RestController
- @RequestMapping - controller and/or method
- @RequestParam, @PathVariable, @RequestBody
- Controller
- @Service
MVC Flow
Data
- JDBC abstractions
- Programmatic and declarative transactions
- @Transactional
- ORM
- Hibernate, JPA, JDO
- OXM
- JAXB, Castor, XMLBeans, JiBX, XStream
- JMS
Testing
- Run application with a different context
- Bean mocks
- Alternate implementations
- Compatible with standard runners
- @RunWith(...)
- E.g.: SpringJUnit4ClassRunner.class
- @ContextConfiguration(...)
- Pass the requested context configurations
Features Configuration
- XML:
- Context: <context:annotation-config/>
- Component scan:
<context:component-scan base-package=”...”/>
- AOP: <aop:aspectj-autoproxy/>
- Transactions: <tx:annotation-driven/>
- MVC: <mvc:annotation-driven/>
- Beans can be configured manually in XML
- Lots of hard (and brittle) work...
Features Configuration
- Java-based:
- Configuration: @Configuration
- Context: @AnnotationDrivenConfig
- Component scan: @ComponentScan(“...”)
- AOP: @EnableAspectJAutoProxy
- Transactions: @EnableTransactionManagement
- MVC: @EnableWebMvc
Spring Boot
- start.spring.io
- Just choose what you need and go
- Config automatically according to libraries in
classpath
- @SpringBootApplication
- @Configuration
- @EnableAutoConfiguration
- @ComponentScan
“You can generally trust Spring
to do the right thing.”
Additional Resources
●http://springtutorials.com/spring-ecosystem
●http://start.spring.io
●https://spring.io/projects
●https://spring.io/guides
●http://docs.spring.io/spring/docs/current/sprin
g-framework-reference/htmlsingle

Contenu connexe

Tendances

Building and Managing Projects with Maven
Building and Managing Projects with MavenBuilding and Managing Projects with Maven
Building and Managing Projects with MavenKhan625
 
Mule connector for ibm® as400
Mule connector for ibm® as400Mule connector for ibm® as400
Mule connector for ibm® as400D.Rajesh Kumar
 
Building and managing java projects with maven part-III
Building and managing java projects with maven part-IIIBuilding and managing java projects with maven part-III
Building and managing java projects with maven part-IIIprinceirfancivil
 
Java spring framework
Java spring frameworkJava spring framework
Java spring frameworkRajiv Gupta
 
Spring - Part 4 - Spring MVC
Spring - Part 4 - Spring MVCSpring - Part 4 - Spring MVC
Spring - Part 4 - Spring MVCHitesh-Java
 
Database component in mule
Database component in muleDatabase component in mule
Database component in muleRajkattamuri
 
Session 43 - Spring - Part 1 - IoC DI Beans
Session 43 - Spring - Part 1 - IoC DI BeansSession 43 - Spring - Part 1 - IoC DI Beans
Session 43 - Spring - Part 1 - IoC DI BeansPawanMM
 
Mule esb
Mule esbMule esb
Mule esbKhan625
 
ADF Anti-Patterns: Dangerous Tutorials
ADF Anti-Patterns: Dangerous TutorialsADF Anti-Patterns: Dangerous Tutorials
ADF Anti-Patterns: Dangerous Tutorialsandrejusb
 
Oracle ADF Architecture TV - Design - ADF Reusable Artifacts
Oracle ADF Architecture TV - Design - ADF Reusable ArtifactsOracle ADF Architecture TV - Design - ADF Reusable Artifacts
Oracle ADF Architecture TV - Design - ADF Reusable ArtifactsChris Muir
 
ADF Mythbusters UKOUG'14
ADF Mythbusters UKOUG'14ADF Mythbusters UKOUG'14
ADF Mythbusters UKOUG'14andrejusb
 
Oracle ADF Architecture TV - Development - Error Handling
Oracle ADF Architecture TV - Development - Error HandlingOracle ADF Architecture TV - Development - Error Handling
Oracle ADF Architecture TV - Development - Error HandlingChris Muir
 
Spring Framework - Core
Spring Framework - CoreSpring Framework - Core
Spring Framework - CoreDzmitry Naskou
 
Struts 2 - Introduction
Struts 2 - Introduction Struts 2 - Introduction
Struts 2 - Introduction Hitesh-Java
 
Introduction to Role Based Administration in WildFly 8
Introduction to Role Based Administration in WildFly 8Introduction to Role Based Administration in WildFly 8
Introduction to Role Based Administration in WildFly 8Dimitris Andreadis
 
WebLogic Server Work Managers and Overload Protection
WebLogic Server Work Managers and Overload ProtectionWebLogic Server Work Managers and Overload Protection
WebLogic Server Work Managers and Overload ProtectionJames Bayer
 
How to use bean as datasource in database connector
How to use bean as datasource in database connectorHow to use bean as datasource in database connector
How to use bean as datasource in database connectorRaviRajuRamaKrishna
 

Tendances (20)

Building and Managing Projects with Maven
Building and Managing Projects with MavenBuilding and Managing Projects with Maven
Building and Managing Projects with Maven
 
Mule connector for ibm® as400
Mule connector for ibm® as400Mule connector for ibm® as400
Mule connector for ibm® as400
 
Building and managing java projects with maven part-III
Building and managing java projects with maven part-IIIBuilding and managing java projects with maven part-III
Building and managing java projects with maven part-III
 
Java spring framework
Java spring frameworkJava spring framework
Java spring framework
 
Spring - Part 4 - Spring MVC
Spring - Part 4 - Spring MVCSpring - Part 4 - Spring MVC
Spring - Part 4 - Spring MVC
 
Database component in mule
Database component in muleDatabase component in mule
Database component in mule
 
Session 43 - Spring - Part 1 - IoC DI Beans
Session 43 - Spring - Part 1 - IoC DI BeansSession 43 - Spring - Part 1 - IoC DI Beans
Session 43 - Spring - Part 1 - IoC DI Beans
 
Mule esb
Mule esbMule esb
Mule esb
 
ADF Anti-Patterns: Dangerous Tutorials
ADF Anti-Patterns: Dangerous TutorialsADF Anti-Patterns: Dangerous Tutorials
ADF Anti-Patterns: Dangerous Tutorials
 
Oracle ADF Architecture TV - Design - ADF Reusable Artifacts
Oracle ADF Architecture TV - Design - ADF Reusable ArtifactsOracle ADF Architecture TV - Design - ADF Reusable Artifacts
Oracle ADF Architecture TV - Design - ADF Reusable Artifacts
 
ADF Mythbusters UKOUG'14
ADF Mythbusters UKOUG'14ADF Mythbusters UKOUG'14
ADF Mythbusters UKOUG'14
 
Oracle ADF Architecture TV - Development - Error Handling
Oracle ADF Architecture TV - Development - Error HandlingOracle ADF Architecture TV - Development - Error Handling
Oracle ADF Architecture TV - Development - Error Handling
 
Spring Framework - Core
Spring Framework - CoreSpring Framework - Core
Spring Framework - Core
 
Struts 2 - Introduction
Struts 2 - Introduction Struts 2 - Introduction
Struts 2 - Introduction
 
Introduction to Role Based Administration in WildFly 8
Introduction to Role Based Administration in WildFly 8Introduction to Role Based Administration in WildFly 8
Introduction to Role Based Administration in WildFly 8
 
JavaCro'14 - Building interactive web applications with Vaadin – Peter Lehto
JavaCro'14 - Building interactive web applications with Vaadin – Peter LehtoJavaCro'14 - Building interactive web applications with Vaadin – Peter Lehto
JavaCro'14 - Building interactive web applications with Vaadin – Peter Lehto
 
WebLogic Server Work Managers and Overload Protection
WebLogic Server Work Managers and Overload ProtectionWebLogic Server Work Managers and Overload Protection
WebLogic Server Work Managers and Overload Protection
 
Spring MVC Framework
Spring MVC FrameworkSpring MVC Framework
Spring MVC Framework
 
Avatar 2.0
Avatar 2.0Avatar 2.0
Avatar 2.0
 
How to use bean as datasource in database connector
How to use bean as datasource in database connectorHow to use bean as datasource in database connector
How to use bean as datasource in database connector
 

En vedette (10)

Spock
SpockSpock
Spock
 
мифы о спарке
мифы о спарке мифы о спарке
мифы о спарке
 
Spring data jee conf
Spring data jee confSpring data jee conf
Spring data jee conf
 
Java garbage collection & GC friendly coding
Java garbage collection  & GC friendly codingJava garbage collection  & GC friendly coding
Java garbage collection & GC friendly coding
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Let's Learn to Talk to GC Logs in Java 9
Let's Learn to Talk to GC Logs in Java 9Let's Learn to Talk to GC Logs in Java 9
Let's Learn to Talk to GC Logs in Java 9
 
Spring
SpringSpring
Spring
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
 
Spring Framework
Spring FrameworkSpring Framework
Spring Framework
 
Java Performance and Profiling
Java Performance and ProfilingJava Performance and Profiling
Java Performance and Profiling
 

Similaire à Spring Framework Essentials

Deep Dive: Alfresco Core Repository (... embedded in a micro-services style a...
Deep Dive: Alfresco Core Repository (... embedded in a micro-services style a...Deep Dive: Alfresco Core Repository (... embedded in a micro-services style a...
Deep Dive: Alfresco Core Repository (... embedded in a micro-services style a...J V
 
GlassFish REST Administration Backend
GlassFish REST Administration BackendGlassFish REST Administration Backend
GlassFish REST Administration BackendArun Gupta
 
Toms introtospring mvc
Toms introtospring mvcToms introtospring mvc
Toms introtospring mvcGuo Albert
 
Boston 2011 OTN Developer Days - Java EE 6
Boston 2011 OTN Developer Days - Java EE 6Boston 2011 OTN Developer Days - Java EE 6
Boston 2011 OTN Developer Days - Java EE 6Arun Gupta
 
GlassFish REST Administration Backend at JavaOne India 2012
GlassFish REST Administration Backend at JavaOne India 2012GlassFish REST Administration Backend at JavaOne India 2012
GlassFish REST Administration Backend at JavaOne India 2012Arun Gupta
 
Spring 3.1: a Walking Tour
Spring 3.1: a Walking TourSpring 3.1: a Walking Tour
Spring 3.1: a Walking TourJoshua Long
 
Spring 3 - Der dritte Frühling
Spring 3 - Der dritte FrühlingSpring 3 - Der dritte Frühling
Spring 3 - Der dritte FrühlingThorsten Kamann
 
Java EE 6 & GlassFish = Less Code + More Power at CEJUG
Java EE 6 & GlassFish = Less Code + More Power at CEJUGJava EE 6 & GlassFish = Less Code + More Power at CEJUG
Java EE 6 & GlassFish = Less Code + More Power at CEJUGArun Gupta
 
Java EE 6 = Less Code + More Power
Java EE 6 = Less Code + More PowerJava EE 6 = Less Code + More Power
Java EE 6 = Less Code + More PowerArun Gupta
 
Java EE 6 & GlassFish = Less Code + More Power @ DevIgnition
Java EE 6 & GlassFish = Less Code + More Power @ DevIgnitionJava EE 6 & GlassFish = Less Code + More Power @ DevIgnition
Java EE 6 & GlassFish = Less Code + More Power @ DevIgnitionArun Gupta
 
Elk-slides-pdf.pdf
Elk-slides-pdf.pdfElk-slides-pdf.pdf
Elk-slides-pdf.pdfHello244729
 
OOW09 Ebs Tuning Final
OOW09 Ebs Tuning FinalOOW09 Ebs Tuning Final
OOW09 Ebs Tuning Finaljucaab
 
MSc Enterprise Systems Development Guest Lecture at UniS (2/12/09)
MSc Enterprise Systems Development Guest Lecture at UniS (2/12/09)MSc Enterprise Systems Development Guest Lecture at UniS (2/12/09)
MSc Enterprise Systems Development Guest Lecture at UniS (2/12/09)Daniel Bryant
 
Станислав Сидоренко «DeviceHive Java Server – миграция на Spring Boot»
Станислав Сидоренко «DeviceHive Java Server – миграция на Spring Boot»Станислав Сидоренко «DeviceHive Java Server – миграция на Spring Boot»
Станислав Сидоренко «DeviceHive Java Server – миграция на Spring Boot»DataArt
 
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 2011Sam Brannen
 
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 BrannenJAX London
 
Java EE 6 & GlassFish 3: Light-weight, Extensible, and Powerful @ Silicon Val...
Java EE 6 & GlassFish 3: Light-weight, Extensible, and Powerful @ Silicon Val...Java EE 6 & GlassFish 3: Light-weight, Extensible, and Powerful @ Silicon Val...
Java EE 6 & GlassFish 3: Light-weight, Extensible, and Powerful @ Silicon Val...Arun Gupta
 
Incorta spark integration
Incorta spark integrationIncorta spark integration
Incorta spark integrationDylan Wan
 
Enterprise Java Web Application Frameworks Sample Stack Implementation
Enterprise Java Web Application Frameworks   Sample Stack ImplementationEnterprise Java Web Application Frameworks   Sample Stack Implementation
Enterprise Java Web Application Frameworks Sample Stack ImplementationMert Çalışkan
 

Similaire à Spring Framework Essentials (20)

Deep Dive: Alfresco Core Repository (... embedded in a micro-services style a...
Deep Dive: Alfresco Core Repository (... embedded in a micro-services style a...Deep Dive: Alfresco Core Repository (... embedded in a micro-services style a...
Deep Dive: Alfresco Core Repository (... embedded in a micro-services style a...
 
GlassFish REST Administration Backend
GlassFish REST Administration BackendGlassFish REST Administration Backend
GlassFish REST Administration Backend
 
Toms introtospring mvc
Toms introtospring mvcToms introtospring mvc
Toms introtospring mvc
 
Boston 2011 OTN Developer Days - Java EE 6
Boston 2011 OTN Developer Days - Java EE 6Boston 2011 OTN Developer Days - Java EE 6
Boston 2011 OTN Developer Days - Java EE 6
 
GlassFish REST Administration Backend at JavaOne India 2012
GlassFish REST Administration Backend at JavaOne India 2012GlassFish REST Administration Backend at JavaOne India 2012
GlassFish REST Administration Backend at JavaOne India 2012
 
Spring 3.1: a Walking Tour
Spring 3.1: a Walking TourSpring 3.1: a Walking Tour
Spring 3.1: a Walking Tour
 
Spring 3 - Der dritte Frühling
Spring 3 - Der dritte FrühlingSpring 3 - Der dritte Frühling
Spring 3 - Der dritte Frühling
 
Java EE 6 & GlassFish = Less Code + More Power at CEJUG
Java EE 6 & GlassFish = Less Code + More Power at CEJUGJava EE 6 & GlassFish = Less Code + More Power at CEJUG
Java EE 6 & GlassFish = Less Code + More Power at CEJUG
 
Java EE 6 = Less Code + More Power
Java EE 6 = Less Code + More PowerJava EE 6 = Less Code + More Power
Java EE 6 = Less Code + More Power
 
Java EE 6 & GlassFish = Less Code + More Power @ DevIgnition
Java EE 6 & GlassFish = Less Code + More Power @ DevIgnitionJava EE 6 & GlassFish = Less Code + More Power @ DevIgnition
Java EE 6 & GlassFish = Less Code + More Power @ DevIgnition
 
Elk-slides-pdf.pdf
Elk-slides-pdf.pdfElk-slides-pdf.pdf
Elk-slides-pdf.pdf
 
OOW09 Ebs Tuning Final
OOW09 Ebs Tuning FinalOOW09 Ebs Tuning Final
OOW09 Ebs Tuning Final
 
MSc Enterprise Systems Development Guest Lecture at UniS (2/12/09)
MSc Enterprise Systems Development Guest Lecture at UniS (2/12/09)MSc Enterprise Systems Development Guest Lecture at UniS (2/12/09)
MSc Enterprise Systems Development Guest Lecture at UniS (2/12/09)
 
Станислав Сидоренко «DeviceHive Java Server – миграция на Spring Boot»
Станислав Сидоренко «DeviceHive Java Server – миграция на Spring Boot»Станислав Сидоренко «DeviceHive Java Server – миграция на Spring Boot»
Станислав Сидоренко «DeviceHive Java Server – миграция на Spring Boot»
 
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
 
Java EE 6 & GlassFish 3: Light-weight, Extensible, and Powerful @ Silicon Val...
Java EE 6 & GlassFish 3: Light-weight, Extensible, and Powerful @ Silicon Val...Java EE 6 & GlassFish 3: Light-weight, Extensible, and Powerful @ Silicon Val...
Java EE 6 & GlassFish 3: Light-weight, Extensible, and Powerful @ Silicon Val...
 
Incorta spark integration
Incorta spark integrationIncorta spark integration
Incorta spark integration
 
Enterprise Java Web Application Frameworks Sample Stack Implementation
Enterprise Java Web Application Frameworks   Sample Stack ImplementationEnterprise Java Web Application Frameworks   Sample Stack Implementation
Enterprise Java Web Application Frameworks Sample Stack Implementation
 
Spring introduction
Spring introductionSpring introduction
Spring introduction
 

Dernier

Gravity concentration_MI20612MI_________
Gravity concentration_MI20612MI_________Gravity concentration_MI20612MI_________
Gravity concentration_MI20612MI_________Romil Mishra
 
Immutable Image-Based Operating Systems - EW2024.pdf
Immutable Image-Based Operating Systems - EW2024.pdfImmutable Image-Based Operating Systems - EW2024.pdf
Immutable Image-Based Operating Systems - EW2024.pdfDrew Moseley
 
Python Programming for basic beginners.pptx
Python Programming for basic beginners.pptxPython Programming for basic beginners.pptx
Python Programming for basic beginners.pptxmohitesoham12
 
Prach: A Feature-Rich Platform Empowering the Autism Community
Prach: A Feature-Rich Platform Empowering the Autism CommunityPrach: A Feature-Rich Platform Empowering the Autism Community
Prach: A Feature-Rich Platform Empowering the Autism Communityprachaibot
 
Robotics Group 10 (Control Schemes) cse.pdf
Robotics Group 10  (Control Schemes) cse.pdfRobotics Group 10  (Control Schemes) cse.pdf
Robotics Group 10 (Control Schemes) cse.pdfsahilsajad201
 
Secure Key Crypto - Tech Paper JET Tech Labs
Secure Key Crypto - Tech Paper JET Tech LabsSecure Key Crypto - Tech Paper JET Tech Labs
Secure Key Crypto - Tech Paper JET Tech Labsamber724300
 
Novel 3D-Printed Soft Linear and Bending Actuators
Novel 3D-Printed Soft Linear and Bending ActuatorsNovel 3D-Printed Soft Linear and Bending Actuators
Novel 3D-Printed Soft Linear and Bending ActuatorsResearcher Researcher
 
Artificial Intelligence in Power System overview
Artificial Intelligence in Power System overviewArtificial Intelligence in Power System overview
Artificial Intelligence in Power System overviewsandhya757531
 
Module-1-(Building Acoustics) Noise Control (Unit-3). pdf
Module-1-(Building Acoustics) Noise Control (Unit-3). pdfModule-1-(Building Acoustics) Noise Control (Unit-3). pdf
Module-1-(Building Acoustics) Noise Control (Unit-3). pdfManish Kumar
 
Comparative study of High-rise Building Using ETABS,SAP200 and SAFE., SAFE an...
Comparative study of High-rise Building Using ETABS,SAP200 and SAFE., SAFE an...Comparative study of High-rise Building Using ETABS,SAP200 and SAFE., SAFE an...
Comparative study of High-rise Building Using ETABS,SAP200 and SAFE., SAFE an...Erbil Polytechnic University
 
Robotics-Asimov's Laws, Mechanical Subsystems, Robot Kinematics, Robot Dynami...
Robotics-Asimov's Laws, Mechanical Subsystems, Robot Kinematics, Robot Dynami...Robotics-Asimov's Laws, Mechanical Subsystems, Robot Kinematics, Robot Dynami...
Robotics-Asimov's Laws, Mechanical Subsystems, Robot Kinematics, Robot Dynami...Sumanth A
 
Theory of Machine Notes / Lecture Material .pdf
Theory of Machine Notes / Lecture Material .pdfTheory of Machine Notes / Lecture Material .pdf
Theory of Machine Notes / Lecture Material .pdfShreyas Pandit
 
multiple access in wireless communication
multiple access in wireless communicationmultiple access in wireless communication
multiple access in wireless communicationpanditadesh123
 
CS 3251 Programming in c all unit notes pdf
CS 3251 Programming in c all unit notes pdfCS 3251 Programming in c all unit notes pdf
CS 3251 Programming in c all unit notes pdfBalamuruganV28
 
Curve setting (Basic Mine Surveying)_MI10412MI.pptx
Curve setting (Basic Mine Surveying)_MI10412MI.pptxCurve setting (Basic Mine Surveying)_MI10412MI.pptx
Curve setting (Basic Mine Surveying)_MI10412MI.pptxRomil Mishra
 
70 POWER PLANT IAE V2500 technical training
70 POWER PLANT IAE V2500 technical training70 POWER PLANT IAE V2500 technical training
70 POWER PLANT IAE V2500 technical trainingGladiatorsKasper
 
Forming section troubleshooting checklist for improving wire life (1).ppt
Forming section troubleshooting checklist for improving wire life (1).pptForming section troubleshooting checklist for improving wire life (1).ppt
Forming section troubleshooting checklist for improving wire life (1).pptNoman khan
 
TEST CASE GENERATION GENERATION BLOCK BOX APPROACH
TEST CASE GENERATION GENERATION BLOCK BOX APPROACHTEST CASE GENERATION GENERATION BLOCK BOX APPROACH
TEST CASE GENERATION GENERATION BLOCK BOX APPROACHSneha Padhiar
 
SOFTWARE ESTIMATION COCOMO AND FP CALCULATION
SOFTWARE ESTIMATION COCOMO AND FP CALCULATIONSOFTWARE ESTIMATION COCOMO AND FP CALCULATION
SOFTWARE ESTIMATION COCOMO AND FP CALCULATIONSneha Padhiar
 

Dernier (20)

Gravity concentration_MI20612MI_________
Gravity concentration_MI20612MI_________Gravity concentration_MI20612MI_________
Gravity concentration_MI20612MI_________
 
Immutable Image-Based Operating Systems - EW2024.pdf
Immutable Image-Based Operating Systems - EW2024.pdfImmutable Image-Based Operating Systems - EW2024.pdf
Immutable Image-Based Operating Systems - EW2024.pdf
 
Python Programming for basic beginners.pptx
Python Programming for basic beginners.pptxPython Programming for basic beginners.pptx
Python Programming for basic beginners.pptx
 
Prach: A Feature-Rich Platform Empowering the Autism Community
Prach: A Feature-Rich Platform Empowering the Autism CommunityPrach: A Feature-Rich Platform Empowering the Autism Community
Prach: A Feature-Rich Platform Empowering the Autism Community
 
Robotics Group 10 (Control Schemes) cse.pdf
Robotics Group 10  (Control Schemes) cse.pdfRobotics Group 10  (Control Schemes) cse.pdf
Robotics Group 10 (Control Schemes) cse.pdf
 
Secure Key Crypto - Tech Paper JET Tech Labs
Secure Key Crypto - Tech Paper JET Tech LabsSecure Key Crypto - Tech Paper JET Tech Labs
Secure Key Crypto - Tech Paper JET Tech Labs
 
Novel 3D-Printed Soft Linear and Bending Actuators
Novel 3D-Printed Soft Linear and Bending ActuatorsNovel 3D-Printed Soft Linear and Bending Actuators
Novel 3D-Printed Soft Linear and Bending Actuators
 
Artificial Intelligence in Power System overview
Artificial Intelligence in Power System overviewArtificial Intelligence in Power System overview
Artificial Intelligence in Power System overview
 
Module-1-(Building Acoustics) Noise Control (Unit-3). pdf
Module-1-(Building Acoustics) Noise Control (Unit-3). pdfModule-1-(Building Acoustics) Noise Control (Unit-3). pdf
Module-1-(Building Acoustics) Noise Control (Unit-3). pdf
 
Comparative study of High-rise Building Using ETABS,SAP200 and SAFE., SAFE an...
Comparative study of High-rise Building Using ETABS,SAP200 and SAFE., SAFE an...Comparative study of High-rise Building Using ETABS,SAP200 and SAFE., SAFE an...
Comparative study of High-rise Building Using ETABS,SAP200 and SAFE., SAFE an...
 
Robotics-Asimov's Laws, Mechanical Subsystems, Robot Kinematics, Robot Dynami...
Robotics-Asimov's Laws, Mechanical Subsystems, Robot Kinematics, Robot Dynami...Robotics-Asimov's Laws, Mechanical Subsystems, Robot Kinematics, Robot Dynami...
Robotics-Asimov's Laws, Mechanical Subsystems, Robot Kinematics, Robot Dynami...
 
Theory of Machine Notes / Lecture Material .pdf
Theory of Machine Notes / Lecture Material .pdfTheory of Machine Notes / Lecture Material .pdf
Theory of Machine Notes / Lecture Material .pdf
 
multiple access in wireless communication
multiple access in wireless communicationmultiple access in wireless communication
multiple access in wireless communication
 
CS 3251 Programming in c all unit notes pdf
CS 3251 Programming in c all unit notes pdfCS 3251 Programming in c all unit notes pdf
CS 3251 Programming in c all unit notes pdf
 
Curve setting (Basic Mine Surveying)_MI10412MI.pptx
Curve setting (Basic Mine Surveying)_MI10412MI.pptxCurve setting (Basic Mine Surveying)_MI10412MI.pptx
Curve setting (Basic Mine Surveying)_MI10412MI.pptx
 
Designing pile caps according to ACI 318-19.pptx
Designing pile caps according to ACI 318-19.pptxDesigning pile caps according to ACI 318-19.pptx
Designing pile caps according to ACI 318-19.pptx
 
70 POWER PLANT IAE V2500 technical training
70 POWER PLANT IAE V2500 technical training70 POWER PLANT IAE V2500 technical training
70 POWER PLANT IAE V2500 technical training
 
Forming section troubleshooting checklist for improving wire life (1).ppt
Forming section troubleshooting checklist for improving wire life (1).pptForming section troubleshooting checklist for improving wire life (1).ppt
Forming section troubleshooting checklist for improving wire life (1).ppt
 
TEST CASE GENERATION GENERATION BLOCK BOX APPROACH
TEST CASE GENERATION GENERATION BLOCK BOX APPROACHTEST CASE GENERATION GENERATION BLOCK BOX APPROACH
TEST CASE GENERATION GENERATION BLOCK BOX APPROACH
 
SOFTWARE ESTIMATION COCOMO AND FP CALCULATION
SOFTWARE ESTIMATION COCOMO AND FP CALCULATIONSOFTWARE ESTIMATION COCOMO AND FP CALCULATION
SOFTWARE ESTIMATION COCOMO AND FP CALCULATION
 

Spring Framework Essentials

  • 1. Spring “Less” is More Based on the official reference docs (v4.3.2)
  • 2. What is it? - Application framework - Inversion of Control (IoC) container - Dependency Injection (DI) - “Ask the framework for the resource” - Many additional (optional) modules - AOP, Web MVC, Data, Security, Mobile, ... - “Alternative” to Java EE - Actually, on top and ahead of it
  • 3. Why is it?.. - Historically, greatly eased application development - Java EE implementations has since caught up nicely - Not held back by standardization committees - Advanced features not yet in the Java EE spec - No need for a full application server - Servlet container is enough - Highly modular and granular DI
  • 6. Bootstrapping - Configuration - XML - Java-based - IoC container init - ApplicationContext - Wiring - Run-time factory
  • 7. Basic XML Configuration <?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"> <import resource="helloOtherWorldConfig.xml"/> <bean id="helloWorld" class="com.world.HelloWorld" scope="prototype" lazy-init="true"> <property name="param1" value="21"/> <property name="param2" ref="helloOtherWorld"/> </bean> </beans>
  • 9. Basic Usage // create and configure beans - XML ApplicationContext context = new ClassPathXmlApplicationContext("helloWorldConfig.xml"); // create and configure beans - Java-based ApplicationContext context = new AnnotationConfigApplicationContext(HelloWorldConfig.class); // retrieve configured instance HelloWorld greeter = context.getBean("helloWorld", HelloWorld.class); // use configured instance String greeting = greeter.greet();
  • 10. Naming - Each bean must have a unique identifier - If none provided in configuration - names are camel-cased - Derived similar to JSON convention: - objectProperty -> objectProperty - ObjectProperty -> objectProperty - OBJECTPROPERTY -> oBJECTPROPERTY
  • 11. Beans - Essentially - POJO - But works with convoluted hierarchies - @Bean + @Configuration / @Component - @Lazy - @Scope - singleton, prototype, request, session - @Profile - …, …, …
  • 12. Beans Wiring - @Autowired - Inferred - Can be advised - Constructor-based DI for mandatory dependencies - Usually - prefer this method - Setter-based DI for optional dependencies - Useful for cases of circular dependencies
  • 13. AOP - Crosscutting concerns - Spring, logging, security, etc. - @Aspect - @Pointcut(“...”) - E.g.: "execution (* com.company.*.*(..)) - JoinPoint - @Before - @After, @AfterReturning, @AfterThrowing - @Around
  • 14. MVC - Model - @Repository - View - @Controller + @ResponseBody - @RestController - @RequestMapping - controller and/or method - @RequestParam, @PathVariable, @RequestBody - Controller - @Service
  • 16. Data - JDBC abstractions - Programmatic and declarative transactions - @Transactional - ORM - Hibernate, JPA, JDO - OXM - JAXB, Castor, XMLBeans, JiBX, XStream - JMS
  • 17. Testing - Run application with a different context - Bean mocks - Alternate implementations - Compatible with standard runners - @RunWith(...) - E.g.: SpringJUnit4ClassRunner.class - @ContextConfiguration(...) - Pass the requested context configurations
  • 18. Features Configuration - XML: - Context: <context:annotation-config/> - Component scan: <context:component-scan base-package=”...”/> - AOP: <aop:aspectj-autoproxy/> - Transactions: <tx:annotation-driven/> - MVC: <mvc:annotation-driven/> - Beans can be configured manually in XML - Lots of hard (and brittle) work...
  • 19. Features Configuration - Java-based: - Configuration: @Configuration - Context: @AnnotationDrivenConfig - Component scan: @ComponentScan(“...”) - AOP: @EnableAspectJAutoProxy - Transactions: @EnableTransactionManagement - MVC: @EnableWebMvc
  • 20. Spring Boot - start.spring.io - Just choose what you need and go - Config automatically according to libraries in classpath - @SpringBootApplication - @Configuration - @EnableAutoConfiguration - @ComponentScan
  • 21. “You can generally trust Spring to do the right thing.”