This is a basic tutorial on Spring core.
Best viewed when animations and transitions are supported, e.g., view in MS Powerpoint. So, please try to view it with animation else the main purpose of this presentation will be defeated.
Spring Boot is a framework for creating stand-alone, production-grade Spring-based applications that can be started using java -jar without requiring any traditional application servers. It is designed to get developers up and running as quickly as possible with minimal configuration. Some key features of Spring Boot include automatic configuration, starter dependencies to simplify dependency management, embedded HTTP servers, security, metrics, health checks and externalized configuration. The document then provides examples of building a basic RESTful web service with Spring Boot using common HTTP methods like GET, POST, PUT, DELETE and handling requests and responses.
Spring boot is a great and relatively a new project from Spring.io. The presentation discusses about basics of spring boot to advance topics. Sample demo apps are available here : https://github.com/bhagwat/spring-boot-samples
Spring Boot is a framework that makes it easy to create stand-alone, production-grade Spring based Applications that can be "just run". It takes an opinionated view of the Spring platform and third-party libraries so that new and existing Spring developers can quickly get started with minimal configuration. Key features include automatic configuration of Spring, embedded HTTP servers, starters for common dependencies, and monitoring endpoints.
Spring Data is a high level SpringSource project whose purpose is to unify and ease the access to different kinds of persistence stores, both relational database systems and NoSQL data stores.
Spring Boot is a framework for creating stand-alone, production-grade Spring based Applications that can be "just run". It provides starters for auto-configuration of common Spring and third-party libraries providing features like Thymeleaf, Spring Data JPA, Spring Security, and testing. It aims to remove boilerplate configuration and promote "convention over configuration" for quick development. The document then covers how to run a basic Spring Boot application, use Rest Controllers, Spring Data JPA, Spring Security, and testing. It also discusses deploying the application on a web server and customizing through properties files.
The document discusses the Java Persistence API (JPA) and Hibernate framework. It provides an overview of JPA's main features, the five steps to implement JPA using Hibernate, and the components that make up Hibernate.
JPA and Hibernate are specifications and frameworks for object-relational mapping (ORM) in Java. JPA is a specification for ORM that is vendor-neutral, while Hibernate is an open-source implementation of JPA. Both use annotations to map Java classes to database tables. JPA queries use JPAQL while Hibernate supports both JPAQL and its own HQL. Additional features covered include relationships, inheritance mapping strategies, custom types, and querying.
Welcome to presentation on Spring boot which is really great and relatively a new project from Spring.io. Its aim is to simplify creating new spring framework based projects and unify their configurations by applying some conventions. This convention over configuration is already successfully applied in so called modern web based frameworks like Grails, Django, Play framework, Rails etc.
Java Spring framework, Dependency Injection, DI, IoC, Inversion of ControlArjun Thakur
Hi, I just prepared a presentation on Java Spring Framework, the topics covered include architecture of Spring framework and it's modules. Spring Core is explained in detail including but not limited to Inversion of Control (IoC), Dependency Injection (DI) etc. Thank you and happy learning. :)
Spring Boot is a framework for creating stand-alone, production-grade Spring based applications that can be "just run". It aims to provide a radically faster and widely accessible starting experience for developing Spring applications. Spring Boot applications can be started using java -jar or traditional WAR deployments and require very little Spring configuration. The document then discusses system requirements, development environment, creating a simple Hello World application, using Spring Boot Admin to monitor applications, configuring databases, Spring Data JPA, REST controllers, caching with EhCache, building web applications with Thymeleaf, and project structure.
This document provides an overview of Spring and Spring Boot frameworks. It discusses the history of Java and Spring, how Spring provides inversion of control and dependency injection. It also covers Spring MVC for web applications, Spring Data for data access, and how Spring Boot aims to simplify configuration. The document concludes with discussing some next steps including looking at Spring Security, Spring Cloud, and using Spring with other JVM languages.
The document discusses Java Persistence API (JPA) and Hibernate, which are frameworks that help map objects to relational databases and resolve the impedance mismatch between object-oriented and relational models. JPA is a specification that providers like Hibernate implement. Hibernate is an object/relational mapping tool that provides object/relational mapping, object/relational persistence services, and query capabilities. It generates database schemas from object models and vice versa. The document also provides examples of performing basic CRUD operations using JPA and SQL.
Youtube Link: https://youtu.be/CXTiwkZVoZI
( Microservices Architecture Training: https://www.edureka.co/microservices-architecture-training )
This Edureka's PPT on Spring Boot Interview Questions talks about the top questions asked related to Spring Boot.
Follow us to never miss an update in the future.
YouTube: https://www.youtube.com/user/edurekaIN
Instagram: https://www.instagram.com/edureka_learning/
Facebook: https://www.facebook.com/edurekaIN/
Twitter: https://twitter.com/edurekain
LinkedIn: https://www.linkedin.com/company/edureka
Castbox: https://castbox.fm/networks/505?country=in
Spring Boot is a framework that makes it easy to create stand-alone, production-grade Spring based applications that you can "just run". It allows you to create stand-alone applications, embed Tomcat/Jetty directly with no need to deploy WAR files, and provides starter POMs to simplify configuration. Spring Boot applications are run by adding a spring-boot-gradle-plugin and can then be run as an executable JAR. Features include REST endpoints, security, external configuration, and production monitoring via Actuators.
Maven is a build tool that can manage a project's build process, dependencies, documentation and reporting. It uses a Project Object Model (POM) file to store build configuration and metadata. Maven has advantages over Ant like built-in functionality for common tasks, cross-project reuse, and support for conditional logic. It works by defining the project with a POM file then running goals bound to default phases like compile, test, package to build the project.
Hibernate is an object-relational mapping tool for Java that allows developers to persist Java objects to a relational database in a transparent way. It provides transparent persistence without needing to flatten objects or write database specific code. Hibernate uses an object-oriented query language that closely resembles SQL to retrieve and manipulate persisted objects.
This document provides an overview of Spring Boot, including:
- Comparisons between Spring Boot, Spring, and Spring MVC.
- The advantages of Spring Boot like auto-configuration and ease of use.
- How to get started with Spring Boot using start.spring.io and key annotations.
- How Spring Boot handles dependencies, logging, exceptions, and databases.
- References additional resources on Spring Boot.
The document provides an introduction to the Spring Framework. It discusses that Spring is a lightweight application framework that addresses all tiers of an application and provides services traditionally provided by application servers. It can integrate with J2EE servers and replace some of their services. Spring brings consistency to application structure and provides elegant integration with standard interfaces like Hibernate and Struts. The core of Spring provides inversion of control/dependency injection and an AOP framework. It also includes service abstraction layers for transaction management, data access, emailing, and remoting. Spring integrates well with web frameworks and provides its own MVC framework.
The document discusses the Spring Framework, an open source application framework for Java. It provides inversion of control and dependency injection to manage application objects. The core package provides dependency injection while other packages provide additional features like transaction management, ORM integration, AOP, and MVC web development. The framework uses an IoC container to manage application objects called beans through configuration metadata.
This document introduces vFabric Core Spring education, which includes core Spring education, Spring professional certification, and continuing education. The core Spring education is a 4-day instructor-led class covering fundamental Spring topics. Students then receive a voucher to take the SpringSource certified Spring professional exam. Continuing education options include additional 3-4 day instructor-led classes on advanced Spring topics.
Introduction to Spring Framework and Spring IoCFunnelll
An introduction to the building blocks of the Spring framework. The presentation focuses on Spring Inverse of Control Container (IoC) ,how it used in the LinkedIn stack, how it integrates with other frameworks and how it works with your JUnit testing.
Maven Presentation - SureFire vs FailSafeHolasz Kati
Maven is a build automation tool used primarily for Java projects. It can be used for building and managing any Java-based project. Maven uses a project object model (POM) to manage a project's build, reporting and documentation from a central piece of information. The POM contains details like dependencies, plugins, repositories used, and other configuration details. Maven projects follow a standard directory structure and use the POM file to define build properties and dependencies. Maven manages dependencies by downloading required JARs from repositories. It supports profiles to customize builds for different environments. Common plugins include those for testing, packaging, site generation and other goals.
Apache maven, a software project management toolRenato Primavera
This document discusses Apache Maven, an open-source tool for managing software projects and automating common software project tasks such as compiling source code, running tests, packaging, and deploying artifacts. It describes how Maven uses a Project Object Model (POM) file to manage a project's build, reporting and documentation from a central configuration. It also outlines key Maven concepts like the POM, lifecycles, phases, dependencies, repositories, inheritance, and multi-module projects.
Spring Framework 4 is an open source application framework for Java. It was created to make enterprise Java development easier by promoting best practices. Some key features of Spring include dependency injection for loose coupling, declarative transactions, and aspect oriented programming for separation of concerns. The Spring framework uses an inversion of control container and aspect-oriented programming to configure and manage objects.
Spring Framework 5 introduces major updates to support reactive programming and non-blocking architectures. It fully supports Java 8 and 9 features and provides both annotation-based and functional programming styles. New additions include support for HTTP/2, reactive streams with Project Reactor, and functional Kotlin extensions. These changes help address challenges of blocking IO and improve latency, resource utilization, and code imperativity for reactive applications.
The document discusses test integration and provides examples of how to use the jIntegrity library to simplify database integration testing. It shows how jIntegrity can load test data from XML files, execute SQL statements to insert, update, delete and clean data, and be configured through properties files. jIntegrity aims to provide flexibility, organization and reuse through its API and helper classes to help automate common database operations for integration testing.
Hibernate framework simplifies the development of java application to interact with the database. Hibernate is an open source, lightweight, ORM (Object Relational Mapping) tool.
An ORM tool simplifies the data creation, data manipulation and data access. It is a programming technique that maps the object to the data stored in the database.
Hibernate framework simplifies the development of java application to interact with the database. Hibernate is an open source, lightweight, ORM (Object Relational Mapping) tool.
An ORM tool simplifies the data creation, data manipulation and data access. It is a programming technique that maps the object to the data stored in the database.
The document discusses various aspects of dependency injection (DI) in Spring, including:
- Using constructor and setter injection to inject dependencies into beans
- Declaring inner beans and aliases
- Initializing collections in beans
- Understanding different bean scopes like singleton and prototype
- Autowiring bean dependencies
- Making beans aware of their names and the application context
- Inheriting properties from parent bean definitions
- Lifecycle callbacks for initializing and destroying beans
- Method injection and lookup method injection
The document provides examples and explanations of these different DI features in Spring. It describes how Spring manages object dependencies and allows the container to inject collaborating objects.
Alexey Buzdin "Maslow's Pyramid of Android Testing"IT Event
You all know what tests are. You all know you need to write them. But also you know it’s hard to start writing tests for mobile app thus you usually neglect it. Let’s look into Android automation testing, what technologies and approaches we can use to have a complete Maslow's Pyramid for testing. Unit Testing, Integration Testing, UI Automation, Mocking etc.
This document compares Python and Java in terms of code cleanliness, speed, and frameworks. For code cleanliness, it argues that Python code is cleaner than equivalent Java code due to optional parameters and default values. For speed, it shows Java outperforms Python in a Project Euler problem but Python is faster in another example. Finally, it lists many popular Python and Java frameworks for web development.
Java ppt Gandhi Ravi (gandhiri@gmail.com)Gandhi Ravi
This document provides an introduction to the Java programming language. It discusses that Java is an object-oriented, platform-independent language that uses a runtime environment and API. It explains how Java code is compiled and executed. It also covers Java applications, data types, operators, keywords, variables, constructors, inheritance, polymorphism, arrays and other core Java concepts. The document provides examples to illustrate different Java programming concepts.
Mahika Tutorials sharing Java Spring Framework Tutorials. You can visit our YouTube Page for Video Session also : https://www.youtube.com/c/mahikatutorials
SpringOne Platform 2017
Sébastien Deleuze, Pivotal
"In this new talk, I will explain why Spring <3 Kotlin and how you can leverage Spring official support for Kotlin (in Framework, Boot, Data) to build your next Spring project more efficiently and with more pleasure.
I will describe gradually how you can transform your Spring Boot 1.0 Java + Javascript project with into a Spring Boot 2.0 pure Kotlin project running on top of the new WebFlux functional web framework."
The document provides an overview of JavaScript design patterns including creational, structural, and behavioral patterns. It discusses common patterns like the module pattern, prototype pattern, factory pattern, decorator pattern, observer pattern, and more. Code examples are provided to demonstrate how each pattern works in JavaScript.
The document provides an overview of the Android infrastructure and development environment. It discusses:
- The layers of an Android application including presentation, application logic, and domain layers.
- Key aspects of the Android runtime including the Dalvik VM, app lifecycle, resources and context handling.
- Libraries that help with common tasks like compatibility, fragments, networking and dependency injection including the Android Support Library, ActionBarSherlock, Retrofit, Dagger and RoboGuice.
- Alternatives for data storage like SQLite and ORM libraries like ORMLite and GreenDAO.
- Options for testing Android apps using the DVM, JVM, Robotium and Robolectric.
The document provides an overview of the Android infrastructure and key concepts:
(1) It describes the layers of an Android application including the presentation layer, application logic layer, and domain layer.
(2) It explains important Android concepts such as the Android runtime environment, Dalvik virtual machine, application lifecycle and activities, and use of contexts.
(3) It discusses alternatives for common tasks like dependency injection with RoboGuice and Dagger, handling resources and views with ButterKnife and AndroidAnnotations, and accessing data with SQLite and ORMLite.
(4) It also briefly covers testing approaches on the DVM and JVM using AndroidTestCase, Robotium, and Robolectric
EJB 3.0 introduced a simplified programming model for enterprise Java with plain old Java objects (POJOs), dependency injection, and metadata-driven configuration. The new features include support for POJO session beans with simplified lifecycles, the Java Persistence API (JPA) for object-relational mapping, and the ability to define interceptors for cross-cutting concerns.
The document discusses key concepts in Java including classes, objects, variables, data types, comments, access modifiers, inheritance, and more. It provides examples of how to define classes with methods and variables, create objects, access instance variables and methods, use access modifiers like public and private, extend classes, and override methods. Constructors are shown being used to initialize objects.
2012 yılında, o sırada gerçekleştireceğiniz bir projede hangi dili kullanacağımız konusunda kararsız kalmıştık. Ben Python yanlısıydım ve görüşümü desteklemek için Java ve Python'u yapısal ve performans olarak kıyaslayan nu sunumu hazırlamıştım. Benzer kararsızlıklar yaşayanlara faydalı olmasını umuyorum.
The easy way to develop Java applications has always been the standard stack (Spring, JEE, SQL) that confirms the LAMP equivalent in Java-speak. This presentation compares this model with a real use case based on Guice, Jersey and AppEngine.
this ppt tells you about what is spring in java. how to use spring? and what are the main methods of spring class? For more info and free java projects visit : http://s4al.com/category/study-java/
This ppt tells about spring class in java. what spring class have, all the methods in brief. for more info please visit : http://s4al.com/category/study-java/
Spring Boot is a framework for building stand-alone, production-grade Spring based Applications that can be "just run". It takes an opinionated view of the Spring platform and third-party libraries so developers can get started with minimum fuss. Some key features include an embedded HTTP server and automatic configuration support. Spring Boot applications can be started using Java -jar or executed using Gradle/Maven and can be packaged as an executable jar or war file for deployment. The document also discusses using Spring Boot with databases, profiles, Spring Data, GORM, views and some miscellaneous topics.
7 Most Powerful Solar Storms in the History of Earth.pdfEnterprise Wired
Solar Storms (Geo Magnetic Storms) are the motion of accelerated charged particles in the solar environment with high velocities due to the coronal mass ejection (CME).
Implementations of Fused Deposition Modeling in real worldEmerging Tech
The presentation showcases the diverse real-world applications of Fused Deposition Modeling (FDM) across multiple industries:
1. **Manufacturing**: FDM is utilized in manufacturing for rapid prototyping, creating custom tools and fixtures, and producing functional end-use parts. Companies leverage its cost-effectiveness and flexibility to streamline production processes.
2. **Medical**: In the medical field, FDM is used to create patient-specific anatomical models, surgical guides, and prosthetics. Its ability to produce precise and biocompatible parts supports advancements in personalized healthcare solutions.
3. **Education**: FDM plays a crucial role in education by enabling students to learn about design and engineering through hands-on 3D printing projects. It promotes innovation and practical skill development in STEM disciplines.
4. **Science**: Researchers use FDM to prototype equipment for scientific experiments, build custom laboratory tools, and create models for visualization and testing purposes. It facilitates rapid iteration and customization in scientific endeavors.
5. **Automotive**: Automotive manufacturers employ FDM for prototyping vehicle components, tooling for assembly lines, and customized parts. It speeds up the design validation process and enhances efficiency in automotive engineering.
6. **Consumer Electronics**: FDM is utilized in consumer electronics for designing and prototyping product enclosures, casings, and internal components. It enables rapid iteration and customization to meet evolving consumer demands.
7. **Robotics**: Robotics engineers leverage FDM to prototype robot parts, create lightweight and durable components, and customize robot designs for specific applications. It supports innovation and optimization in robotic systems.
8. **Aerospace**: In aerospace, FDM is used to manufacture lightweight parts, complex geometries, and prototypes of aircraft components. It contributes to cost reduction, faster production cycles, and weight savings in aerospace engineering.
9. **Architecture**: Architects utilize FDM for creating detailed architectural models, prototypes of building components, and intricate designs. It aids in visualizing concepts, testing structural integrity, and communicating design ideas effectively.
Each industry example demonstrates how FDM enhances innovation, accelerates product development, and addresses specific challenges through advanced manufacturing capabilities.
Paradigm Shifts in User Modeling: A Journey from Historical Foundations to Em...Erasmo Purificato
Slide of the tutorial entitled "Paradigm Shifts in User Modeling: A Journey from Historical Foundations to Emerging Trends" held at UMAP'24: 32nd ACM Conference on User Modeling, Adaptation and Personalization (July 1, 2024 | Cagliari, Italy)
Fluttercon 2024: Showing that you care about security - OpenSSF Scorecards fo...Chris Swan
Have you noticed the OpenSSF Scorecard badges on the official Dart and Flutter repos? It's Google's way of showing that they care about security. Practices such as pinning dependencies, branch protection, required reviews, continuous integration tests etc. are measured to provide a score and accompanying badge.
You can do the same for your projects, and this presentation will show you how, with an emphasis on the unique challenges that come up when working with Dart and Flutter.
The session will provide a walkthrough of the steps involved in securing a first repository, and then what it takes to repeat that process across an organization with multiple repos. It will also look at the ongoing maintenance involved once scorecards have been implemented, and how aspects of that maintenance can be better automated to minimize toil.
Transcript: Details of description part II: Describing images in practice - T...BookNet Canada
This presentation explores the practical application of image description techniques. Familiar guidelines will be demonstrated in practice, and descriptions will be developed “live”! If you have learned a lot about the theory of image description techniques but want to feel more confident putting them into practice, this is the presentation for you. There will be useful, actionable information for everyone, whether you are working with authors, colleagues, alone, or leveraging AI as a collaborator.
Link to presentation recording and slides: https://bnctechforum.ca/sessions/details-of-description-part-ii-describing-images-in-practice/
Presented by BookNet Canada on June 25, 2024, with support from the Department of Canadian Heritage.
INDIAN AIR FORCE FIGHTER PLANES LIST.pdfjackson110191
These fighter aircraft have uses outside of traditional combat situations. They are essential in defending India's territorial integrity, averting dangers, and delivering aid to those in need during natural calamities. Additionally, the IAF improves its interoperability and fortifies international military alliances by working together and conducting joint exercises with other air forces.
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - MydbopsMydbops
This presentation, delivered at the Postgres Bangalore (PGBLR) Meetup-2 on June 29th, 2024, dives deep into connection pooling for PostgreSQL databases. Aakash M, a PostgreSQL Tech Lead at Mydbops, explores the challenges of managing numerous connections and explains how connection pooling optimizes performance and resource utilization.
Key Takeaways:
* Understand why connection pooling is essential for high-traffic applications
* Explore various connection poolers available for PostgreSQL, including pgbouncer
* Learn the configuration options and functionalities of pgbouncer
* Discover best practices for monitoring and troubleshooting connection pooling setups
* Gain insights into real-world use cases and considerations for production environments
This presentation is ideal for:
* Database administrators (DBAs)
* Developers working with PostgreSQL
* DevOps engineers
* Anyone interested in optimizing PostgreSQL performance
Contact info@mydbops.com for PostgreSQL Managed, Consulting and Remote DBA Services
Quantum Communications Q&A with Gemini LLM. These are based on Shannon's Noisy channel Theorem and offers how the classical theory applies to the quantum world.
Are you interested in dipping your toes in the cloud native observability waters, but as an engineer you are not sure where to get started with tracing problems through your microservices and application landscapes on Kubernetes? Then this is the session for you, where we take you on your first steps in an active open-source project that offers a buffet of languages, challenges, and opportunities for getting started with telemetry data.
The project is called openTelemetry, but before diving into the specifics, we’ll start with de-mystifying key concepts and terms such as observability, telemetry, instrumentation, cardinality, percentile to lay a foundation. After understanding the nuts and bolts of observability and distributed traces, we’ll explore the openTelemetry community; its Special Interest Groups (SIGs), repositories, and how to become not only an end-user, but possibly a contributor.We will wrap up with an overview of the components in this project, such as the Collector, the OpenTelemetry protocol (OTLP), its APIs, and its SDKs.
Attendees will leave with an understanding of key observability concepts, become grounded in distributed tracing terminology, be aware of the components of openTelemetry, and know how to take their first steps to an open-source contribution!
Key Takeaways: Open source, vendor neutral instrumentation is an exciting new reality as the industry standardizes on openTelemetry for observability. OpenTelemetry is on a mission to enable effective observability by making high-quality, portable telemetry ubiquitous. The world of observability and monitoring today has a steep learning curve and in order to achieve ubiquity, the project would benefit from growing our contributor community.
AC Atlassian Coimbatore Session Slides( 22/06/2024)apoorva2579
This is the combined Sessions of ACE Atlassian Coimbatore event happened on 22nd June 2024
The session order is as follows:
1.AI and future of help desk by Rajesh Shanmugam
2. Harnessing the power of GenAI for your business by Siddharth
3. Fallacies of GenAI by Raju Kandaswamy
Sustainability requires ingenuity and stewardship. Did you know Pigging Solutions pigging systems help you achieve your sustainable manufacturing goals AND provide rapid return on investment.
How? Our systems recover over 99% of product in transfer piping. Recovering trapped product from transfer lines that would otherwise become flush-waste, means you can increase batch yields and eliminate flush waste. From raw materials to finished product, if you can pump it, we can pig it.
Coordinate Systems in FME 101 - Webinar SlidesSafe Software
If you’ve ever had to analyze a map or GPS data, chances are you’ve encountered and even worked with coordinate systems. As historical data continually updates through GPS, understanding coordinate systems is increasingly crucial. However, not everyone knows why they exist or how to effectively use them for data-driven insights.
During this webinar, you’ll learn exactly what coordinate systems are and how you can use FME to maintain and transform your data’s coordinate systems in an easy-to-digest way, accurately representing the geographical space that it exists within. During this webinar, you will have the chance to:
- Enhance Your Understanding: Gain a clear overview of what coordinate systems are and their value
- Learn Practical Applications: Why we need datams and projections, plus units between coordinate systems
- Maximize with FME: Understand how FME handles coordinate systems, including a brief summary of the 3 main reprojectors
- Custom Coordinate Systems: Learn how to work with FME and coordinate systems beyond what is natively supported
- Look Ahead: Gain insights into where FME is headed with coordinate systems in the future
Don’t miss the opportunity to improve the value you receive from your coordinate system data, ultimately allowing you to streamline your data analysis and maximize your time. See you there!
2. Agenda – what to do in this Spring
Dependency Injection
Overview of Spring Framework
Various injections and their usages in detail
Bean scope
Bean wiring
Inner bean
Bean properties
Bean life cycle
Bean auto wiring
Spring Annotation
2
Pushan Bhattacharya
3. High Dependency = High Responsibility
public class Tiger {
public void eat() {
System.out.println(“Do not
disturb”);
}
}
public class MainClass {
public static void main(String…
args) {
Tiger t = new Tiger();
t.eat();
}
}
3
o Requirement: Change Tiger to
Lion.
o Me: Urggghhh. Too many
changes.
1. Standalone Lion class
2. Change the object
declaration to Lion
3. Change the reference
4. Compile again
5. Test
Pushan Bhattacharya
4. A bit less dependency
public interface Animal {
void eat();
}
public class Tiger implements Animal {
@Override
public void eat() {
System.out.println(“Do not disturb”);
}
}
public class MainClass {
public static void main(String… args) {
Animal a = new Tiger();
a.eat();
}
}
4
o Requirement: Change Tiger to
Lion.
o Me: Ufff. Again some changes.
1. Lion implements Animal
2. Change the object
declaration to Lion
3. Change the reference
4. Compile again
5. Test
Pushan Bhattacharya
5. Dependency Injection
public interface Animal {
void eat();
}
public class Tiger implements Animal {
@Override
public void eat() {
System.out.println(“Do not disturb”);
}
}
public class MainClass {
public static void main(String… args) {
ApplicationContext aC = new ClassPathXmlApplicationContext(“wildLife.xml”);
Animal a = (Animal) aC.getBean(“animal”);
a.eat();
}
}
wildLife.xml
<bean id = “animal” class = “Tiger” />
5
o Requirement: Change Tiger to
Lion.
o Me: Ok. Small change.
1. Lion implements Animal
2. Change bean class to Lion
3. Change the reference
4. Compile again
5. Test
Pushan Bhattacharya
6. So what is Spring?
IoC container
Lightweight framework
Fully modularized (High decoupling)
Considered an alternative / replacement for the
Enterprise JavaBean (EJB) model
Flexible
Programmers decide how to program
Not exclusive to Java (e.g. .NET)
Solutions to typical coding busywork
JDBC
LDAP
Web Services
6
Pushan Bhattacharya
7. What Spring offers?
Dependency Injection (DI)
DI is implemented through IoC (Inversion of Control)
Aspect Oriented Programming
Runtime injection-based
Portable Service Abstractions
The rest of spring
ORM, DAO, Web MVC, Web, etc.
Allows access to these without knowing how they actually work
Easily testable
7
Pushan Bhattacharya
8. What is a bean?
A Bean is a class that has only state but no behavior
A Bean must contain a no-argument constructor
A Bean should be serialized
8
Class Bean
Pushan Bhattacharya
9. Spring Framework Architecture
9
Pushan Bhattacharya
SPRING CORE CONTAINER
T
E
S
T
BeansCore Context
Expression
Language
DATA ACCESS
INTEGRATION
Spring ORM
Spring DAO
WEB LAYER
Spring WEB
Services
SPRING WEB
MVC
FRAMEWORK
SPRING
AOP
10. Spring Bean Configuration
10
Pushan Bhattacharya
<?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-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd“ >
<bean id = “animal” class = “com.pushan.spring.beans.Tiger“ >
<property name = “msg” value = “Eating now“ />
</bean>
<!--
.
.
.
-->
</beans>
11. Spring IoC Container
11
Pushan Bhattacharya
Bean / POJO /
Application Class
Bean Configuration
Metadata
Completely Configured
Application
Ready to Use
Spring IoC
Container
Registered
Input
Output
1
2
3
12. Spring IoC Container contd…
12
BeanFactory ApplicationContext
The simplest factory, mainly for DI The advanced and more complex factory
Used when resources are limited, e.g., mobile,
applets etc.
Used elsewhere and has the below features,
1> Enterprise aware functions
2> Publish application events to listeners
3> Wire and dispose beans on request
org.springframework.beans.factory.BeanFactory org.springframework.context.ApplicationContext
XmlBeanFactory factory = new
XmlBeanFactory (new
ClassPathResource(“wildLife.xml"));
ApplicationContext aC = new
ClassPathXmlApplicationContext(“wildLi
fe.xml”);
Pushan Bhattacharya
13. Injection Methods
Setter Injection
Pass dependencies in via property setters (e.g., Spring)
Constructor Injection
Pass dependencies in via constructor (e.g., Spring)
Interface Injection
Pass dependencies in via interfaces (e.g., Avalon)
13
public class MainClass {
public static void main(String…
args) {
ApplicationContext aC = new
ClassPathXmlApplicationContext(“wild
Life.xml”);
Animal a = (Animal)
aC.getBean(“animal”);
a.eat();
wildLife.xml
<bean id = “animal” class
= “Tiger” />
Pushan Bhattacharya
14. Setter Injection
In the <bean>, Specify <property> tag.
14
public class College {
private String collegeId;
private int totalStudents;
public String getCollegeId() {
return collegeId;
}
public void setCollegeId(String
collegeId) {
this.collegeId = collegeId;
}
public int getTotalStudents() {
return totalStudents;
}
public void setTotalStudents(int
totalStudents) {
this.totalStudents =
totalStudents;
}
public class MyClass {
private static final String MY_COLLEGE =
"myCollege";
public static void main(String... args) {
ApplicationContext ctx = new
ClassPathXmlApplicationContext("springConfig.xml"
College col = (College) ctx.getBean(MY_COLLEGE);
System.out.println("College Id: " +
col.getCollegeId());
System.out.println("Total Students: " +
col.getTotalStudents());
}
}
<bean id="myCollege"
class="com.pushan.study.spring.beans.College"
>
<property name="collegeId"
value="123Abc"/>
<property name="totalStudents"
Pushan Bhattacharya
15. Constructor Injection
15
In the <bean>, Specify <constructor-arg>
public class College {
private String collegeId;
private int
totalStudents;
public void College (int
tS, String cI) {
this.totalStudents = tS;
this.collegeId = cI;
}
public String
getCollegeId(){
return collegeId;
}
public int
getTotalStudents() {
return totalStudents;
public class MyClass {
private static final String MY_COLLEGE =
"myCollege";
public static void main(String... args) {
ApplicationContext ctx = new
ClassPathXmlApplicationContext("springConfig.xml
");
College col = (College) ctx.getBean(MY_COLLEGE);
System.out.println("College Id: " +
col.getCollegeId());
System.out.println("Total Students: " +
col.getTotalStudents());
}
}
<bean id="myCollege"
class="com.pushan.study.spring.beans.College"
>
<constructor-arg type=“int” value=“500”/>
<constructor-arg type=“java.lang.String”
value=“123Abc”/>
Pushan Bhattacharya
16. Constructor Injection Illustrated
The ‘value’ attribute is mandatory and rest are
optional, e.g., ‘type’
Constructor Injection can automatically cast the
value to the desired ‘known’ type
By default the ‘type’ of the ‘value’ is ‘java.lang.String’
(if not specified explicitly)
Constructor injection does not interpret ordering of
the arguments specified
16
Pushan Bhattacharya
17. Constructor Injection Ambiguity 1
17
<bean id="myCollege" class="com.pushan.College">
<constructor-arg value=“500”/>
<constructor-arg value=“123Abc”/>
</bean>
public class College {
private String collegeId;
private int totalStudents;
private String collegeAdd;
public College (int totalStudents, String collegeId){
this.totalStudents = totalStudents;
this.collegeId = collegeId;
}
public College (String collegeAdd, String collegeId){
this.collegeAdd = collegeAdd;
this.collegeId = collegeId;
}
}
Which constructor will be called?
Pushan Bhattacharya
18. Constructor Injection Ambiguity 1 Solution
18
<bean id="myCollege" class="com.pushan.College">
<constructor-arg value=“500” type=“int”/>
<constructor-arg value=“123Abc” type=“java.lang.String”/>
</bean>
The ‘type’ of the value is specified
public class College {
private String collegeId;
private int totalStudents;
private String collegeAdd;
public College (int totalStudents, String collegeId){
this.totalStudents = totalStudents;
this.collegeId = collegeId;
}
public College (String collegeAdd, String collegeId){
this.collegeAdd = collegeAdd;
this.collegeId = collegeId;
}
}
Pushan Bhattacharya
19. Constructor Injection Ambiguity 2
19
<bean id="myCollege" class="com.pushan.College">
<constructor-arg value=“500” type=“int”/>
<constructor-arg value=“123Abc” type=“java.lang.String”/>
</bean>
public class College {
private String collegeId;
private int totalStudents;
private String collegeAdd;
public College (int totalStudents, String collegeId){
this.totalStudents = totalStudents;
this.collegeId = collegeId;
}
public College (String collegeAdd, int totalStudents){
this.totalStudents = totalStudents;
this. collegeAdd = collegeAdd;
}
}
Which constructor will be called?
Pushan Bhattacharya
20. Constructor Injection Ambiguity 2 Solution
20
The ‘index’ of the value is specified
<bean id="myCollege" class="com.pushan.College">
<constructor-arg value=“500” type=“int” index=“0”/>
<constructor-arg value=“123Abc” type=“java.lang.String” index=“1”/>
</bean>
public class College {
private String collegeId;
private int totalStudents;
private String collegeAdd;
public College (int totalStudents, String collegeId){
this.totalStudents = totalStudents;
this.collegeId = collegeId;
}
public College (String collegeAdd, int totalStudents){
this.totalStudents = totalStudents;
this. collegeAdd = collegeAdd;
}
}
Pushan Bhattacharya
21. Bean Scope 1 – Object Type (Part I)
Pushan Bhattacharya
21
Bean Scope Description
singleton Single instance of bean in every getBean() call [Default]
prototype New instance of bean in every getBean() call
request Single instance of bean per HTTP request
session Single instance of bean per HTTP session
global-session Single instance of bean per global HTTP session
thread Single instance of bean per thread
custom Customized scope
Valid in the context of
web-aware
ApplicationContext
Added in Spring 3.0
We will look into
‘singleton’ and
‘prototype’ scopes
only
22. Bean Scope 1 – Object Type (Part II)
Mainly bean can be of two types, viz.,
1. Singleton (e.g., <bean scope=“singleton” … />)
2. Prototype (e.g., <bean scope=“prototype” … />)
A ‘singleton’ bean is created once in the Spring container.
This ‘singleton’ bean is given every time when referred. It is
garbage collected when the container shuts down.
A ‘prototype’ bean means a new object in every request. It is
garbage collected in the normal way, i.e., when there is no
reference for this object.
By default every bean is singleton if not specified explicitly.
22
Pushan Bhattacharya
24. Bean Reference (wiring)
Through setter or constructor injection we can refer to
another bean which has its own separate definition.
24
public class Person{
// ...
}
public class Location{
private String city;
public Location (String c){
this.city = c;
}
// ...
}
public class A {
private String msg;
private Person owner;
private Location address;
// getters and setters ...
}
<bean id="person"
class="Person" /> <bean id="location"
class="Location">
<constructor-arg
value="Kolkata"
type="java.lang.String" />
</bean>
<bean id="a" class="A">
<property name="msg" value="hello"/>
<property name="owner" ref="person"/>
<property name="address">
<ref bean="location" />
</property>
</bean>
Pushan Bhattacharya
25. Circular Dependency
25
Bean A Bean B
public class A {
private B b;
public A (B b) {
this.b = b;
}
}
public class B {
private A a;
public B (A a) {
this.a = a;
}
}
<bean id=“a” class=“A”>
<constructor-arg ref=“b” />
</bean>
<bean id=“b” class=“B”>
<constructor-arg ref=“a” />
</bean>
Pushan Bhattacharya
26. Inner Bean
Inner bean is also a bean reference.
A bean defined within another bean.
The inner bean is fully local to the outer bean.
The inner bean has prototype scope.
26
<bean id=“a” class=“A”>
<property name=“address”>
<bean class=“Location”>
<property name=“city” value=“Kolkata”/>
<property name=“zip” value=“700006”/>
</bean>
</property>
</bean>
public class A {
private Location address;
// getters and setters …
}
public class Location {
private String city, zip;
// getters and setters …
}
Pushan Bhattacharya
27. Injecting Collection
27
Tag Name
Inner Tag
Name
Java Collection
Type
Specification
<list> <value> java.util.List<E>
Allows duplicate
entries
<map> <entry> java.util.Map<K, V>
Key-Value pair of
any object type
<set> <value> java.util.Set<E>
Does not allow
duplicate entries
<props> <prop> java.util.Properties
Key-Value pair of
type ‘String’
Pushan Bhattacharya
28. So, lets inject some collection then …
28
<bean id=“animalCollection" class=“AnimalCollection">
<property name=“animalList">
<list>
<value>Tiger</value>
<value>Lion</value>
<value>Tiger</value>
</list>
</property>
<property name=“animalSet">
<set>
<value>Lion</value>
<value>Tiger</value>
<value>Lion</value>
</set>
</property>
<property name="animalMap">
<map>
<entry key="1" value=“Tiger"/>
<entry key="2" value=“Lion"/>
<entry key="3" value=“Tiger"/>
</map>
</property>
<property name="animalProp">
<props>
<prop key="one">Lion</prop>
<prop key="two">Tiger</prop>
<prop key="three">Lion</prop>
</props>
</property>
</bean>
public class AnimalCollection {
List<String> animalList;
Set<String> animalSet;
Map<String, String> animalMap;
Properties animalProp;
// getters and setters ...
}
public class MainClass {
public static void main(String… args) {
ApplicationContext ctx = new
ClassPathXmlApplicationContext(“wildLife.xml”);
AnimalCollection aC =(AnimalCollection)
ctx.getBean("animalCollection");
System.out.println(“animalList :” + aC.getAnimalList());
System.out.println(“animalSet:” + aC.getAnimalSet());
System.out.println(“animalMap:” + aC.getAnimalMap());
System.out.println(“animalProp:” + aC.getAnimalProp());
}
}
animalList :[Tiger, Lion, Tiger]
animalSet :[Lion, Tiger]
animalMap :{1=Tiger, 2=Lion, 3=Tiger}
animalProp :{one=Lion, two=Tiger, three=Lion}
Bean
definition
for DI
Bean
Test class
Output
Pushan Bhattacharya
29. Constructor v/s Setter Injection
Setter injection gets preference over constructor
injection when both are specified
Constructor injection cannot partially initialize values
Circular dependency can be achieved by setter
injection
Security is lesser in setter injection as it can be
overridden
Constructor injection fully ensures dependency
injection but setter injection does not
Setter injection is more readable
29
Pushan Bhattacharya
30. Bean Properties
30
Tag Name Description Example
id Unique Id <bean id=“person” … />
name Unique Name <bean name=“lion” … />
class Fully qualified Java class name <bean class=“a.b.C” … />
scope Bean object type <bean scope=“singleton” … />
constructor-arg Constructor injection <constructor-arg value=“a” />
property Setter injection <property name=“a” … />
autowire Automatic Bean referencing <bean autowire=“byName” … />
lazy-init Create a bean lazily (at its first request) <bean lazy-init=“true” … />
init-method
A callback method just after bean
creation
<bean init-method=“log” … />
destroy-method A callback just before bean destruction <bean destroy-method=“log” … />
Pushan Bhattacharya
31. Bean Life Cycle Callbacks
31
org.springframework.beans.factory.InitializingBean
void afterPropertiesSet () throws Exception;
public class MyBean implements
InitializingBean {
public void afterPropertiesSet () {
// Initialization work
}
}
<bean id=“myBean"
class=“MyBean" init-method="init"/>
public class MyBean {
public void init () {
// Initialization work
}
}
org.springframework.beans.factory.DisposableBean
void destroy () throws Exception;
public class MyBean implements
DisposableBean {
public void destroy () {
// Destruction work
}
}
<bean id=“myBean"
class=“MyBean" destroy-method=“des"/>
public class MyBean {
public void des () {
// Destruction work
}
}
Pushan Bhattacharya
32. Beans Auto-Wiring
32
Mode Description Example
no No auto wiring of beans Default
byName Auto wire beans by property name <bean autowire=“byName” … />
byType Auto wire beans by property type <bean autowire=“byType” … />
constructor Auto wire beans by constructor <bean autowire=“constructor” … />
autodetect First try by constructor, then by type <bean autowire=“autodetect” … />
Spring container can auto wire beans
In this case, there is no need to specify <property/> and/or
<constructor-arg/> tags
It decreases the amount of xml configuration
Pushan Bhattacharya
Removed
in Spring
3.0
33. Auto wire by Name
33
public class Person {
// ...
}
public class Location {
private String city;
public Location (String city) {
this.city = city;
}
// ...
}
public class A {
private String msg;
private Person person;
private Location location;
// getters and setters ...
}
<bean id="person"
class="Person" />
<bean id="location"
class="Location">
<constructor-arg value="Kolkata"
type="java.lang.String" />
</bean>
<bean id="a" class="A“ autowire=“byName”>
<property name="msg" value="hello" />
</bean>
Pushan Bhattacharya
34. Auto wire by Type
34
public class Person {
// ...
}
public class Location {
private String city;
public Location (String city) {
this.city = city;
}
// ...
}
public class A {
private String msg;
private Person owner;
private Location address;
// getters and setters ...
}
<bean id="person"
class="Person" />
<bean id="location"
class="Location">
<constructor-arg value="Kolkata"
type="java.lang.String" />
</bean>
<bean id="a" class="A“ autowire=“byType”>
<property name="msg" value="hello" />
</bean>
Pushan Bhattacharya
<!-- The below bean definition will destroy
the uniqueness of beans byType, hence
Spring will give exception. -->
<bean id=“person2" class=“Person”/>
35. Auto wire by Constructor
35
public class Person {
// ...
}
public class Location {
private String city;
public Location (String city) {
this.city = city;
}
// ...
}
public class A {
private String msg;
private Person owner;
private Location address;
public A (String m, Person o, Location a){
…
}
}
<bean id="person"
class="Person" />
<bean id="location"
class="Location">
<constructor-arg value="Kolkata"
type="java.lang.String" />
</bean>
<bean id="a" class="A“ autowire=“constructor”>
<property name="msg" value="hello" />
</bean>
Pushan Bhattacharya
36. Spring Auto-wiring Bottleneck
36
Disadvantage Description
Overriding beans configuration
If the bean configuration is specified explicitly then it overrides
the bean auto wiring configuration
Unable to wire primitive types
Auto wiring is applicable only for beans and not for simple
properties like primitives, String etc.
Auto wiring has confusing nature
Explicit wiring or manual wiring of beans is easier to
understand than auto wiring. It is preferred to use explicit
wiring if possible.
Partial wiring is not possible
Auto wiring will always try to wire all the beans through setter
or constructor. It cannot be used for partial wiring.
Spring auto wiring has certain disadvantages or limitations,
given below.
Pushan Bhattacharya
37. @Spring (annotation = start)
Evolved in Spring 2.0 (@Required).
Developed and became famous from Spring 2.5
“Old wine in new bottle” - an alternative of the xml
configuration for bean wiring
Not enabled by default (need explicit enabling)
XML overrides annotation for bean configuration
Sometimes gets treated as an anti-pattern since change
of annotation configuration needs compilation of code
IDE support
37
Pushan Bhattacharya
39. @Required
39
• Applicable to only setter methods. • Values by name.
• Strict checking.
public class Boy {
private String name;
private int age;
@Required
public void setName(String name){
this.name = name;
}
@Required
public void setAge(int age){
this.age = age;
}
// getters ...
}
<bean id=“boy” class=“Boy”>
<property name=“name” value=“Rony”/>
<property name=“age” value=“10”/>
</bean>
<bean id=“boy” class=“Boy”>
<property name=“name” value=“Rony”/>
</bean>
Property 'age' is required for bean
'boy'
Pushan Bhattacharya
40. @Autowired
40
• Applicable to methods, fields and
constructors
• Wiring by type.
• ‘required’ attribute
public class Boy {
private String name;
private int age;
// getters and setters ...
}
<bean id=“boy” class=“Boy”>
<property name=“name” value=“Rony”/>
<property name=“age” value=“10”/>
</bean>
public class College {
private String collegeId;
@Autowired
private Boy student;
public void setCollegeId(String cI){
this.collegeId = cI;
}
// getters ...
}
<bean id=“college” class=“College”>
<property name=“collegeId” value=“1A”/>
</bean>
public class College {
private String collegeId;
@Autowired(required=false)
private Boy student;
// ...
}
No setter
needed for
autowiring
on field
‘student’
auto wiring
becomes
optional
Pushan Bhattacharya
41. @Qualifier
41
• Solution to @Autowired for type ambiguity
public class Boy {
private String name;
private int age;
// getters and setters ...
}
public class College {
private String collegeId;
@Autowired
private Boy student;
public void setCollegeId(String cI){
this.collegeId = cI;
}
// getters ...
}
<bean id=“boy1” class=“Boy”>
<qualifier value=“rony”/>
<property name=“name” value=“Rony”/>
<property name=“age” value=“10”/>
</bean>
<bean id=“college” class=“College”>
<property name=“collegeId” value=“1A”/>
</bean>
<bean id=“boy2” class=“Boy”>
<qualifier value=“tony”/>
<property name=“name” value=“Tony”/>
<property name=“age” value=“8”/>
</bean>
@Qualifier(value=“tony”)
Qualifier
value
• If <qualifier/> is not configured, then searches
with bean id/name. But if specified, it will
always search with qualifier only.
Pushan Bhattacharya
42. @Resource, @PostConstruct, @PreDestroy
@PostConstruct is an alternative of the init-method.
@PreDestroy is an alternative of the destroy-method.
@Resource(name=“<beanName>”) is used for auto wiring by name.
@Resource can be applied in field, argument and methods.
If no ‘name’ attribute is specified in @Resource, then the name is derived from
the field, setter method etc.
42
<bean id=“boy1” class=“Boy”>
<property name=“name” value=“Rony”/>
<property name=“age” value=“10”/>
</bean>
<bean id=“college” class=“College”>
<property name=“collegeId” value=“1A”/>
</bean>
<bean id=“boy2” class=“Boy”>
<property name=“name” value=“Tony”/>
<property name=“age” value=“8”/>
</bean>
public class College {
private String collegeId;
@Resource(name=“boy1”)
private Boy student;
// getters and setters ...
}
Pushan Bhattacharya
43. @Configuration & @Bean (Part I)
43
@Configuration
public class AnimalConfig{
@Bean
public Lion lion(){
return new Lion();
}
@Bean
public Tiger tiger(){
Tiger t = new Tiger();
t.doInit();
return t;
}
}
<bean id=“lion” class=“Lion” />
<bean id=“tiger” class=“Tiger”
init-method=“doInit” />
public class MainTest{
public static void main(String[] a){
ApplicationContext aC = new
AnnotationConfigApplicationContext(An
imalConfig.class);
Tiger t = aC.getBean(Tiger.class);
Lion l = aC.getBean(Lion.class);
// ...
}
}
Pushan Bhattacharya
44. @Configuration & @Bean (Part II)
44
@Configuration
public class LionConfig{
@Bean(destroyMethod=“clear”)
public Lion lion(){
return new Lion();
}
}
@Configuration
public class TigerConfig{
@Bean(initMethod=“doInit”)
public Tiger tiger(){
return new Tiger();
}
}
<bean id=“lion” class=“Lion”
destroy-method=“clear” />
<bean id=“tiger” class=“Tiger”
init-method=“doInit” />
public class MainTest{
public static void main(String[] a){
ApplicationContext aC = new
AnnotationConfigApplicationContext();
aC.register(LionConfig.class,
TigerConfig.class);
aC.refresh();
// ...
}
}
Pushan Bhattacharya
45. @Configuration & @Bean (Part III)
45
Pushan Bhattacharya
@Configuration
public class TigerConfig{
@Bean
public Tiger tiger(){
return new Tiger();
}
}
@Configuration
@Import(TigerConfig.class)
public class LionConfig{
@Bean
public Lion lion(){
return new Lion();
}
}
@Configuration
public class TigerConfig{
@Bean(name=“cat”)
@Scope(“prototype”)
public Tiger tiger(){
return new Tiger();
}
}
<bean id=“cat”
class=“Tiger”
scope=“prototype” />
46. Try Yourself
Are ‘Dependency Injection’ and ‘Inversion of Control’
same? Give reason for the answer.
How to achieve circular dependency via both setter and
constructor injection?
How to declare the <property> of the bean together with
the bean definition in a single line?
Why does an inner bean have the default scope as
‘prototype’?
46
Pushan Bhattacharya