In this session you will learn:
Understand Spring framework overview & its salient features
Spring concepts (IoC container / DI)
Spring-AOP basics
Spring ORM / Spring DAO overview
Spring Web / MVC overview
For more information, visit: https://www.mindsmapped.com/courses/software-development/java-developer-training-for-beginners/
Spring MVC 3.0 Framework
Objective:
1. Introduce Spring MVC Module
2. Learn about Spring MVC Components (Dispatcher, Handler mapping, Controller, View Resolver, View)
Slides:
1. What Is Spring?
2. Why use Spring?
3. By the way, just what is MVC?
4. MVC Architecture
5. Spring MVC Architecture
7. Spring MVC Components
8. DispatcherServlet
9. DispatcherServlet Architecture.........
.........................................................
Presentation explain about
Spring Boot vs Spring vs Spring MVC,
Advantages,
Where to start and how does Spring boot work ?,
Dependency Management,
Logging,
Exception Handling,
Database Handling.
in Spring boot.
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.
"Learn All Aspects Of Java Spring Framework step by step, Enhance your skills & Launch Your Career, On-Demand Course affordable price & classes on virtually every topic.Try Before You Buy
for java spring online training visit: https://goo.gl/P15Dbn"
Spring MVC 3.0 Framework
Objective:
1. Introduce Spring MVC Module
2. Learn about Spring MVC Components (Dispatcher, Handler mapping, Controller, View Resolver, View)
Slides:
1. What Is Spring?
2. Why use Spring?
3. By the way, just what is MVC?
4. MVC Architecture
5. Spring MVC Architecture
7. Spring MVC Components
8. DispatcherServlet
9. DispatcherServlet Architecture.........
.........................................................
Presentation explain about
Spring Boot vs Spring vs Spring MVC,
Advantages,
Where to start and how does Spring boot work ?,
Dependency Management,
Logging,
Exception Handling,
Database Handling.
in Spring boot.
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.
"Learn All Aspects Of Java Spring Framework step by step, Enhance your skills & Launch Your Career, On-Demand Course affordable price & classes on virtually every topic.Try Before You Buy
for java spring online training visit: https://goo.gl/P15Dbn"
Introduction to the Spring Framework:
Generar description
IoC container
Dependency Injection
Beans scope and lifecycle
Autowiring
XML and annotation based configuration
Additional features
This presentation is about Spring MVC. Topics covered in this session are:
1. HTTP Servlet
2. What is Spring MVC?
3. MVC Architecture
4. Request Processing Workflow in Spring MVC
5. Spring Web Application Context
6. Spring MVC Configuration
7. Important Annotations
Introduction to angular with a simple but complete projectJadson Santos
A simple front end project with angular. Its show how to create your first components, include bootstrap templates, create routes and build the project to production.
Getting started with the reactjs, basics of reactjs, introduction of reactjs, core concepts of reactjs and comparison with the other libraries/frameworks
In this Java Spring Training session, you will learn Spring – Inversion of Control, Dependency Injection and Bean definitions. Topics covered in this session are:
For more information, visit this link:
Spring Framework
• Core Container
• Data Access/Integration
• Web Layer
• Spring Setup
• Key features
• Spring Bean
• Dependency Injection
• Relation between DI and IoC
• Spring IoC Containers
• Spring DI
https://www.mindsmapped.com/courses/software-development/spring-fundamentals-learn-spring-framework-and-spring-boot/
Quick introduction to Spring Framework. Following are the topics I have included in this presentations:
1. Introduction to Software Framework
2. What is Spring Framework?
3. Spring Framework History
4. Spring Framework Architecture
5. Why Spring?
6. Spring Framework Ecosystem
A simple tutorial for understanding the basics of angular JS. Very useful for the beginners. Also useful for the quick revision. Very attractive design for the tutorial of angular js.
Overview of Spring Boot for the rapid development of Java Applications and Microservices. More information can be found at : https://www.spiraltrain.nl/course-spring-boot-development/?lang=en
Hybernat and structs, spring classes in mumbai
best Hybernat and structs, spring classes in mumbai with job assistance.
our features are:
expert guidance by it industry professionals
lowest fees of 5000
practical exposure to handle projects
well equiped lab
after course resume writing guidance
Introduction to the Spring Framework:
Generar description
IoC container
Dependency Injection
Beans scope and lifecycle
Autowiring
XML and annotation based configuration
Additional features
This presentation is about Spring MVC. Topics covered in this session are:
1. HTTP Servlet
2. What is Spring MVC?
3. MVC Architecture
4. Request Processing Workflow in Spring MVC
5. Spring Web Application Context
6. Spring MVC Configuration
7. Important Annotations
Introduction to angular with a simple but complete projectJadson Santos
A simple front end project with angular. Its show how to create your first components, include bootstrap templates, create routes and build the project to production.
Getting started with the reactjs, basics of reactjs, introduction of reactjs, core concepts of reactjs and comparison with the other libraries/frameworks
In this Java Spring Training session, you will learn Spring – Inversion of Control, Dependency Injection and Bean definitions. Topics covered in this session are:
For more information, visit this link:
Spring Framework
• Core Container
• Data Access/Integration
• Web Layer
• Spring Setup
• Key features
• Spring Bean
• Dependency Injection
• Relation between DI and IoC
• Spring IoC Containers
• Spring DI
https://www.mindsmapped.com/courses/software-development/spring-fundamentals-learn-spring-framework-and-spring-boot/
Quick introduction to Spring Framework. Following are the topics I have included in this presentations:
1. Introduction to Software Framework
2. What is Spring Framework?
3. Spring Framework History
4. Spring Framework Architecture
5. Why Spring?
6. Spring Framework Ecosystem
A simple tutorial for understanding the basics of angular JS. Very useful for the beginners. Also useful for the quick revision. Very attractive design for the tutorial of angular js.
Overview of Spring Boot for the rapid development of Java Applications and Microservices. More information can be found at : https://www.spiraltrain.nl/course-spring-boot-development/?lang=en
Hybernat and structs, spring classes in mumbai
best Hybernat and structs, spring classes in mumbai with job assistance.
our features are:
expert guidance by it industry professionals
lowest fees of 5000
practical exposure to handle projects
well equiped lab
after course resume writing guidance
Spring-
Spring framework is an open source Java platform that provides comprehensive infrastructure support for developing robust Java applications very easily and very rapidly. Spring framework was initially written by Rod Johnson and was first released under the Apache 2.0 license in June 2003.
Spring provides a very clean division between controllers, JavaBean models, and views.
Spring's MVC is very flexible. Unlike Struts, which forces your Action and Form objects into concrete inheritance (thus taking away your single shot at concrete inheritance in Java), Spring MVC is entirely based on interfaces. Furthermore, just about every part of the Spring MVC framework is configurable via plugging in your own interface. Of course we also provide convenience classes as an implementation option.
Spring, like WebWork, provides interceptors as well as controllers, making it easy to factor out behavior common to the handling of many requests.
Spring MVC is truly view-agnostic. You don't get pushed to use JSP if you don't want to; you can use Velocity, XLST or other view technologies. If you want to use a custom view mechanism – for example, your own templating language – you can easily implement the Spring View interface to integrate it.
Spring Controllers are configured via IoC like any other objects. This makes them easy to test, and beautifully integrated with other objects managed by Spring.
Spring MVC web tiers are typically easier to test than Struts web tiers, due to the avoidance of forced concrete inheritance and explicit dependence of controllers on the dispatcher servlet.
The web tier becomes a thin layer on top of a business object layer. This encourages good practice. Struts and other dedicated web frameworks leave you on your own in implementing your business objects; Spring provides an integrated framework for all tiers of your application.
AMC Squarelearning Bangalore is the best training institute for a career development. it had students from various parts of the country and even few were from West African countries.
Introduction to J2EE framework . Gives the primary knowledge about the framework involves in J2EE based web development . This is like Struts , Hibernate , spring ,JSF etc.
Spring tutorial for beginners - Learn Java Spring Framework version 3.1.0 starting from environment setup, inversion of control (IoC), dependency injection, bean scopes, bean life cycle, inner beans, autowiring, different modules, aspect oriented programming (AOP), database access (JDBC), Transaction Management, Web MVC framework, Web Flow, Exception handling, EJB integration and Sending email etc.
This was from the IBM Interconnect Conference in 2017 - it contains best practices and recommendations for things to think about when migrating to microservices
In this session you will learn:
While Loop
Do While Loop
For more information, visit: https://www.mindsmapped.com/courses/software-development/java-developer-training-for-beginners/
In this session you will learn:
Intoduction to WebServices
Interoperability
XML
UDDI – Universal discovery description and Integration
Conversion—java to soap message
Writing a web service
Contract vs service
WSDL generation
For more information, visit: https://www.mindsmapped.com/courses/software-development/java-developer-training-for-beginners/
In this session you will learn:
Conversion of one data type to another.
Implicit ( lower data type to higher data type )
Explicit ( higher data type to lower data type ) .
For more information, visit: https://www.mindsmapped.com/courses/software-development/java-developer-training-for-beginners/
In this session you will learn:
MVC
Spring MVC
Configuring web.xml
Creating Controller
Registering controller with dispatcher-servlet
Mapping requests to controller
Rendering response to View
For more information, visit: https://www.mindsmapped.com/courses/software-development/java-developer-training-for-beginners/
In this session you will learn:
HTTP Protocol
HttpSession API
Destroying the session of webapp
Cookies
Session Management using Cookie
Url Rewriting
For more information, visit: https://www.mindsmapped.com/courses/software-development/java-developer-training-for-beginners/
In this session you will learn:
Understand Servlet life cycle
For more information, visit: https://www.mindsmapped.com/courses/software-development/java-developer-training-for-beginners/
In this session you will learn:
Roy fielding has authored REST specification.
REST webservices
For more information, visit: https://www.mindsmapped.com/courses/software-development/java-developer-training-for-beginners/
In this session you will learn:
Understand Request Dispatcher
JSP
For more information, visit: https://www.mindsmapped.com/courses/software-development/java-developer-training-for-beginners/
In this session you will learn:
Poly- many
morphism –forms.
An entity existing in more than one form.
methods,
objects.
For more information, visit: https://www.mindsmapped.com/courses/software-development/java-developer-training-for-beginners/
In this session you will learn:
Model View and Controller architecture
Model-Business data
View- Presentation logic
Controller-servlet
Separation of business logic from presentation logic
For more information, visit: https://www.mindsmapped.com/courses/software-development/java-developer-training-for-beginners/
In this session you will learn:
Understand polymorphism
For more information, visit: https://www.mindsmapped.com/courses/software-development/java-developer-training-for-beginners/
Mapping Classes with Relational DatabasesAathikaJava
In this session you will learn:
Mapping Properties
Entity Type Vs ValueTypes
Mapping Collections
Relationship in hibernate
One-To-One
One-To-One Mapping
One-To-Many
Many-to-Many
For more information, visit: https://www.mindsmapped.com/courses/software-development/java-developer-training-for-beginners/
In this session you will learn:
Java History
Features of Java
Java Versions
Application Area
For more information, visit: https://www.mindsmapped.com/courses/software-development/java-developer-training-for-beginners/
In this session you will learn:
Encapsulation
Inheritance
For more information, visit: https://www.mindsmapped.com/courses/software-development/java-developer-training-for-beginners/
In this session you will learn:
Introduction to Hibernate
Hibernate Architecture
The Persistence Lifecycle
Getting Started with Hibernate
Relationships and Associations
Advanced Mapping Concepts
Hibernate Queries
Hibernate Transactions
Hibernate Extensions
Hibernate Cache
For more information, visit: https://www.mindsmapped.com/courses/software-development/java-developer-training-for-beginners/
In this session you will learn:
Filter API
Configuring filter
DISPATCHER
For more information, visit: https://www.mindsmapped.com/courses/software-development/java-developer-training-for-beginners/
In this session you will learn:
Understanding Encapsulation
For more information, visit: https://www.mindsmapped.com/courses/software-development/java-developer-training-for-beginners/
State of ICS and IoT Cyber Threat Landscape Report 2024 previewPrayukth K V
The IoT and OT threat landscape report has been prepared by the Threat Research Team at Sectrio using data from Sectrio, cyber threat intelligence farming facilities spread across over 85 cities around the world. In addition, Sectrio also runs AI-based advanced threat and payload engagement facilities that serve as sinks to attract and engage sophisticated threat actors, and newer malware including new variants and latent threats that are at an earlier stage of development.
The latest edition of the OT/ICS and IoT security Threat Landscape Report 2024 also covers:
State of global ICS asset and network exposure
Sectoral targets and attacks as well as the cost of ransom
Global APT activity, AI usage, actor and tactic profiles, and implications
Rise in volumes of AI-powered cyberattacks
Major cyber events in 2024
Malware and malicious payload trends
Cyberattack types and targets
Vulnerability exploit attempts on CVEs
Attacks on counties – USA
Expansion of bot farms – how, where, and why
In-depth analysis of the cyber threat landscape across North America, South America, Europe, APAC, and the Middle East
Why are attacks on smart factories rising?
Cyber risk predictions
Axis of attacks – Europe
Systemic attacks in the Middle East
Download the full report from here:
https://sectrio.com/resources/ot-threat-landscape-reports/sectrio-releases-ot-ics-and-iot-security-threat-landscape-report-2024/
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf91mobiles
91mobiles recently conducted a Smart TV Buyer Insights Survey in which we asked over 3,000 respondents about the TV they own, aspects they look at on a new TV, and their TV buying preferences.
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Ramesh Iyer
In today's fast-changing business world, Companies that adapt and embrace new ideas often need help to keep up with the competition. However, fostering a culture of innovation takes much work. It takes vision, leadership and willingness to take risks in the right proportion. Sachin Dev Duggal, co-founder of Builder.ai, has perfected the art of this balance, creating a company culture where creativity and growth are nurtured at each stage.
JMeter webinar - integration with InfluxDB and GrafanaRTTS
Watch this recorded webinar about real-time monitoring of application performance. See how to integrate Apache JMeter, the open-source leader in performance testing, with InfluxDB, the open-source time-series database, and Grafana, the open-source analytics and visualization application.
In this webinar, we will review the benefits of leveraging InfluxDB and Grafana when executing load tests and demonstrate how these tools are used to visualize performance metrics.
Length: 30 minutes
Session Overview
-------------------------------------------
During this webinar, we will cover the following topics while demonstrating the integrations of JMeter, InfluxDB and Grafana:
- What out-of-the-box solutions are available for real-time monitoring JMeter tests?
- What are the benefits of integrating InfluxDB and Grafana into the load testing stack?
- Which features are provided by Grafana?
- Demonstration of InfluxDB and Grafana using a practice web application
To view the webinar recording, go to:
https://www.rttsweb.com/jmeter-integration-webinar
Let's dive deeper into the world of ODC! Ricardo Alves (OutSystems) will join us to tell all about the new Data Fabric. After that, Sezen de Bruijn (OutSystems) will get into the details on how to best design a sturdy architecture within ODC.
The Art of the Pitch: WordPress Relationships and SalesLaura Byrne
Clients don’t know what they don’t know. What web solutions are right for them? How does WordPress come into the picture? How do you make sure you understand scope and timeline? What do you do if sometime changes?
All these questions and more will be explored as we talk about matching clients’ needs with what your agency offers without pulling teeth or pulling your hair out. Practical tips, and strategies for successful relationship building that leads to closing the deal.
UiPath Test Automation using UiPath Test Suite series, part 3DianaGray10
Welcome to UiPath Test Automation using UiPath Test Suite series part 3. In this session, we will cover desktop automation along with UI automation.
Topics covered:
UI automation Introduction,
UI automation Sample
Desktop automation flow
Pradeep Chinnala, Senior Consultant Automation Developer @WonderBotz and UiPath MVP
Deepak Rai, Automation Practice Lead, Boundaryless Group and UiPath MVP
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...DanBrown980551
Do you want to learn how to model and simulate an electrical network from scratch in under an hour?
Then welcome to this PowSyBl workshop, hosted by Rte, the French Transmission System Operator (TSO)!
During the webinar, you will discover the PowSyBl ecosystem as well as handle and study an electrical network through an interactive Python notebook.
PowSyBl is an open source project hosted by LF Energy, which offers a comprehensive set of features for electrical grid modelling and simulation. Among other advanced features, PowSyBl provides:
- A fully editable and extendable library for grid component modelling;
- Visualization tools to display your network;
- Grid simulation tools, such as power flows, security analyses (with or without remedial actions) and sensitivity analyses;
The framework is mostly written in Java, with a Python binding so that Python developers can access PowSyBl functionalities as well.
What you will learn during the webinar:
- For beginners: discover PowSyBl's functionalities through a quick general presentation and the notebook, without needing any expert coding skills;
- For advanced developers: master the skills to efficiently apply PowSyBl functionalities to your real-world scenarios.
Epistemic Interaction - tuning interfaces to provide information for AI supportAlan Dix
Paper presented at SYNERGY workshop at AVI 2024, Genoa, Italy. 3rd June 2024
https://alandix.com/academic/papers/synergy2024-epistemic/
As machine learning integrates deeper into human-computer interactions, the concept of epistemic interaction emerges, aiming to refine these interactions to enhance system adaptability. This approach encourages minor, intentional adjustments in user behaviour to enrich the data available for system learning. This paper introduces epistemic interaction within the context of human-system communication, illustrating how deliberate interaction design can improve system understanding and adaptation. Through concrete examples, we demonstrate the potential of epistemic interaction to significantly advance human-computer interaction by leveraging intuitive human communication strategies to inform system design and functionality, offering a novel pathway for enriching user-system engagements.
2. Page 1Classification: Restricted
Agenda
• Understand Spring framework overview & its salient features
• Spring concepts (IoC container / DI)
• Spring-AOP basics
• Spring ORM / Spring DAO overview
• Spring Web / MVC overview
3. Page 2Classification: Restricted
Why a new framework?
• Because of many problems with traditional J2EE Architecture
• Complexity
• EJB, JNDI, JTA, JDBC etc
• Too many APIs
• EJB is over used
• Simply lots of code
• Petstore as an example
• Much of the code is “Plumbing code”
• Heavy weight runtime environment
• Hard to Unit Test
• Components need to be explicitly deployed to be able to run, even
for testing
• Slow change-deploy-test cycle
4. Page 3Classification: Restricted
Enter Lightweight Containers
• Frameworks are central to modern J2EE development
• Many projects encounter the same problems
• Service location
• Consistent exception handling
• Parameterizing application code…
• J2EE “out of the box” does not provide a complete (or ideal)
programming model
• Result:
• many in-house frameworks
• Expensive to maintain and develop
• Better to share experience across many projects
• Choose Opensource framework
5. Page 4Classification: Restricted
How do Lightweight Containers Work?
• Inversion of Control/Dependency Injection
• Sophisticated configuration for POJOs
• Aspect Oriented Programming (AOP)
• Provide declarative services to POJOs
• Out-of-the box (transaction management, security) or custom
(auditing)
• Aim to provide a consistent framework for development
• The Spring Framework and HiveMind are the most compelling offerings
• Spring is the most complete, mature and popular
6. Page 5Classification: Restricted
Spring Framework
• The Spring Framework
• Open source project
• Apache 2.0 license
• Initially written by Rod Johnson and Juergen Hoeller
• 21 developers
• Interface21 lead development effort, with seven committers (and
counting), including the two project leads
• Aims
• Simplify J2EE development
• Provide a comprehensive solution to developing applications built on
POJOs
• Provide services for applications ranging from simple web apps up to
large financial/“enterprise” applications
7. Page 6Classification: Restricted
Spring Framework history
• Started 2002/2003 by Rod Johnson and
Juergen Holler
• Started as a framework developed around
Rod Johnson’s book Expert One-on-One J2EE
Design and Development
• Spring 1.0 Released March 2004
• Spring 1.2 - 2005
• Spring 2.0 – October 2006
• Spring 2.5 – November 2007
8. Page 7Classification: Restricted
Spring Framework mission
Mission Statement
• We believe that:
• J2EE should be easier to use
• It is best to program to interfaces, rather than classes. Spring reduces the complexity cost of using
interfaces to zero.
• JavaBeans offer a great way of configuring applications.
• OO design is more important than any implementation technology, such as J2EE.
• Checked exceptions are overused in Java. A framework shouldn't force you to catch exceptions
you're unlikely to be able to recover from.
• Testability is essential, and a framework such as Spring should help make your code easier to test.
Our philosophy is summarized in Expert One-on-One J2EE Design and Development by Rod Johnson.
We aim that:
• Spring should be a pleasure to use
• Your application code should not depend on Spring APIs
• Spring should not compete with good existing solutions, but should foster integration. (For example,
JDO, Toplink, and Hibernate are great O/R mapping solutions. We don't need to develop another
one.)
9. Page 8Classification: Restricted
What is Spring Framework?
Spring is a lightweight, inversion of control and aspect-oriented container
framework.
• Lightweight:
• In terms of both size and overhead.
• Entire framework can be distributed in single JAR file(1MB)
• Processing overhead required is negligible
• Is non intrusive: objects have no dependency on Spring specific classes
• Inversion of Control:
• Promotes loose coupling through use of IoC
• Instead of an object looking up dependencies from a container, the
container gives the dependencies to the object at instantiation
without waiting to be asked (reverse of JNDI)
10. Page 9Classification: Restricted
What is Spring Framework? Contd.
• Aspect-oriented:
• Enables cohesive development by separating application business logic from system
services
• Application objects focus on business logic not other system concerns such as logging,
transaction management
• Container:
• It contains and manages the life cycle of application objects
• You can configure how each of your bean should be created, a single instance
(singleton) or new instance each time (prototype)
• Framework:
• Spring makes it possible to configure and compose complex applications from simpler
components.
• application objects are composed declaratively, typically in an XML file
• Provides infrastructure functionality (transaction management, persistence framework
integration, etc.)
Code which is cleaner, more manageable and easy to test
12. Page 11Classification: Restricted
Spring Framework Overview – contd.
• Core module
• is the most fundamental part of the framework and provides the IoC
and Dependency Injection features
• Defines how beans are created, configured, and managed—more of
the nuts-and-bolts of Spring.
Here you’ll find Spring’s BeanFactory, the heart of any Spring-based
application
• Application Context module
• The core module’s BeanFactory makes Spring a container, but the
context module is what makes it a framework.
• Add supports for i18n messages, application lifecycle events,
validation etc
• Supplies many enterprise services such as e-mail, EJB integration,
remoting, and scheduling and integration with templating frameworks
such as Velocity and FreeMarker.
13. Page 12Classification: Restricted
Spring Framework Overview – contd.
• Spring’s AOP module
• Serves as the basis for developing your own aspects for your Spring-
enabled application.
• Ensures interoperability between Spring and other Java AOP
frameworks
• Supports metadata programming ( aspects can be configured using
annotations)
• JDBC Abstraction and DAO module
• Working with JDBC often results in a lot of boilerplate code
• Abstracts away the boilerplate code and prevents problems that result
from a failure to close database resources
• Uses Spring AOP module to provide Transaction management services
14. Page 13Classification: Restricted
Spring Framework Overview – contd.
• Object/Relational mapping integration module
• Provide hooks into several popular ORM frameworks, including
Hibernate, JDO, and iBATIS SQL Maps.
• Spring’s transaction management supports each of these ORM
frameworks as well as JDBC.
• Spring’s Web module
• Builds on the application context module
• Support for several web-oriented tasks
• e.g. transparently handling multipart requests
• programmatic binding of request parameters to your business
objects
• contains integration support with Jakarta Struts.
• Spring’s MVC framework and can take advantage of Spring’s services
(for e.g. i18n, validation etc.
18. Page 17Classification: Restricted
Bean Factory
• It is an implementation of Factory design pattern
• Instantiation of beans
• Configuration
• Management of one or more beans
• Create associations between collaborating objects as they are
instantiated, thus giving fully configured, ready to use objects
22. Page 21Classification: Restricted
Hello World! – contd.
import java.io.FileInputStream;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
public class HelloApp {
public static void main(String[] args) throws Exception {
BeanFactory factory = new XmlBeanFactory(new
FileInputStream("hello.xml"));
GreetingService greetingService =
(GreetingService) factory.getBean("greetingService");
greetingService.sayGreeting();
}
23. Page 22Classification: Restricted
The Spring IoC container
The
Spring Container
Fully Configured System
Ready for User
Configuration
Metadata
Your Business Objects (POJOs)
24. Page 23Classification: Restricted
What is Inversion of Control (IoC)?
(besides yet another confusing term for a simple concept)
• IoC is all about Object dependencies.
• Traditional "Pull" approach:
• Direct instantiation
• Asking a Factory for an implementation
• Looking up a service via JNDI
• "Push" approach:
• Something outside of the Object "pushes" its dependencies into it.
• The Object has no knowledge of how it gets its dependencies, it just
assumes they are there.
• Hollywood Principle
• Don’t call me, I’ll call you
• Means that the framework calls your code, not the reverse
• The "Push" approach is called "Dependency Injection". (Next slide)
25. Page 24Classification: Restricted
What is Dependency Injection?
• A specialization of Inversion of Control
• The container injects dependencies into object instances using Java
methods
• Dependencies may be collaborating objects or primitive or simple
types
• This is also known as push configuration
• Configuration values are pushed into objects, rather than pulled by
the objects from an environment such as JNDI or a properties file
26. Page 25Classification: Restricted
Inversion of Control Types
• Type 1: Interface injection
• Dependency satisfied by interfaces it implemented (Used by Apache’s
Avalon Framework)
• Type 2: Setter injection
• Dependency satisfied by JavaBean properties and its setter/getter
exposed by a component
• Type 3: Constructor injection
• Dependency satisfied by the component’s constructor
• Spring supports Type 2, Type 3 IoC
• Note: Other Lightweight containers
• Pico Container, Nano Container
• HiveMind
• Avalaon
27. Page 26Classification: Restricted
Dependency Injection using setters
<bean id=”ex1” class=”ExBean1”>
<property name=”bean”>
<ref bean=”ex2”/>
</property>
</bean>
<bean id=”ex2” class=”ExBean2”/>
public class ExBean1 {
private ExBean2 bean;
public void setBean(ExBean2 bean) {
this.bean = bean;
}
}
• The <ref> subelement of <property> helps refer to another bean.
• You can also wire collections such as list, set, map, properties as
subelements of <property>
28. Page 27Classification: Restricted
<bean id="courseService“
class="com.springinaction.service.training.CourseService
Impl">
<property name="studentService">
<ref bean="studentService"/>
</property>
</bean>
The container gives the courseService bean a StudentService bean (through
setStudentService()), thereby freeing CourseServiceImpl from having to
look
up a StudentService bean on its own.
Disadvantages:
• When this type of bean is instantiated, none of its properties have been
set and it could possibly be in an invalid state.
29. Page 28Classification: Restricted
Dependency Injection using Constructors
<bean id="studentService“
class="com.springinaction.training.service.StudentServiceImpl"
>
<constructor-arg>
<ref bean="studentDao"/>
</constructor-arg>
</bean>
Advantages:
• A bean cannot be instantiated without being given all of its dependencies.
It is perfectly valid and ready to use upon instantiation.
• No need for superfluous setter methods. This helps keep the lines of code
at a minimum
• By only allowing properties to be set through the constructor, you are, in
effect, making those properties immutable.
30. Page 29Classification: Restricted
Dependency Injection using Constructors - Contd
Drawback:
• If a bean has several dependencies, the constructor’s parameter list can
be quite lengthy.
• If there are several ways to construct a valid object, it can be hard to
come up with unique constructor. Since constructor signatures vary only
by the number and type of parameters.
• If a constructor takes two or more parameters of the same type, it may
be difficult to determine what each parameter’s purpose is.
• Constructor injection does not lend itself readily to inheritance. A bean’s
constructor will have to pass parameters to super() in order to set private
properties in the parent object.
31. Page 30Classification: Restricted
Why is push better than pull?
• No more ad-hoc lookup
• Code is self-documenting, describing its own dependencies
• Easy to unit test
• No JNDI to stub, properties files to substitute, RDBMS data to set up
• Simply instantiate class in a JUnit test and use setters or constructors
32. Page 31Classification: Restricted
Spring Special Beans
• By implementing certain interfaces Spring can treat some beans
as being special—as being part of the Spring framework itself
• For e.g. Special Beans can be used –
• Become involved in the bean’s and the bean factory’s life
cycles by postprocessing bean configuration
• Load configuration information from external property files
• Load textual messages from property files, including
internationalized messages
• Listen for and respond to application events that are published
by other beans and by the Spring container itself
• Are aware of their identity within the Spring container
33. Page 32Classification: Restricted
For e.g. Externalizing the configuration
Load configuration information from external property files.
<bean id="propertyConfigurer" class="org.springframework.beans.
factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>jdbc.properties</value>
<value>security.properties</value>
</list>
</property>
</bean>
34. Page 33Classification: Restricted
For e.g. Externalizing the configuration contd.
In the jdbc.properties file:
database.url=jdbc:hsqldb:Training
database.driver=org.hsqldb.jdbcDriver
database.user=appUser
database.password=password
Applying the placeholder variables to the data source configuration:
<bean id="dataSource“ class="org.springframework.
jdbc.datasource.DriverManagerDataSource">
<property name="url">
<value>${database.url}</value>
</property>
<property name="driverClassName">
<value>${database.driver}</value>
</property>
<bean>
35. Page 34Classification: Restricted
Special Beans Contd.
• Making Beans Aware.
• By implemementing BeanNameAware and ApplicationContextAware
interfaces, beans can be made aware of their name, their
BeanFactory, and their ApplicationContext, respectively.
• By implementing these interfaces, a bean becomes coupled with
Spring.
39. Page 38Classification: Restricted
What is AOP?
• Paradigm for modularizing crosscutting code
• Code that would otherwise be scattered across multiple methods or
objects can be gathered in one place
40. Page 39Classification: Restricted
Calls to system-wide concerns such as logging and security are often
scattered about in modules where those concerns are not their primary
concern
42. Page 41Classification: Restricted
Before AOP
Client
Method
1. Security check
2. Obtain session
3. Log it to the file
4. Audit trail
5. Start transaction
6. Business Logic
7. Commit
8. Exception handling
43. Page 42Classification: Restricted
AOP applied
Client Method
1. Business Logic
1. Security check
2. Obtain session
3. Log it to the file
4. Audit trail
5. Start transaction
1. Commit
1. Exception handling
44. Page 43Classification: Restricted
AOP Interception
• In the simplest case, think about interception
• Callers invoke a proxy
• A chain of interceptors/advice decorate the method call as execution
flows toward the target
• Interceptors provide services such as transaction management or
security checks
• These services are often specified declaratively
46. Page 45Classification: Restricted
AOP Terms
• Aspect
• The cross-cutting functionality e.g.. Logging
• Jointpoint
• Point in the execution of the application where an aspect can be
plugged in.
• e.g. method being called, an exception being thrown, or even a field
being modified.
• Advice
• Actual implementation of our aspect.It is inserted into our application
at pointcut
• Different types of advice include "around," "before" and "after" advice.
• Pointcut
• A pointcut defines at what joinpoints advice should be applied.
• for e.g. the execution of a method with a certain name
• Some AOP frameworks allow you to create dynamic pointcuts.
47. Page 46Classification: Restricted
AOP Terms
• Introduction
• An introduction allows you to add new methods or attributes to existing
classes
• Target
• A target is the class that is being advised.
• Proxy
• A proxy is the object created by AOP framework after applying advice to
the target object.
• As far as the client objects are concerned, the target object (pre-AOP) and
the proxy object (post-AOP) are the same
• Weaving
• Weaving is the process of applying aspects to a target object to create a
new, proxied object either during target classes’s compile time, classload
time, runtime.
49. Page 48Classification: Restricted
Advantages and Drawbacks of AOP
• Advantages:
• Decoupling between classes
• A clear line between the different application layers
• Reduction of code duplication
• Better support for refactoring
• Drawbacks
• Steep learning curve
• AOP imposes several requirements on the programming language used
50. Page 49Classification: Restricted
Spring AOP
• Aspects written in java
• Pointcut written in XML in Spring Configuration File.
• Spring supports only method joinpoints.
• Other AOP frameworks requires special syntax which is not the case with
Spring
• Other AOP frameworks are AspectJ, AspectWerkz, JbossAOP, EAOP,
DynamicAspects
51. Page 50Classification: Restricted
Creating Advice
• Creating the advice object means writing code to implement the cross
cutting functionality.
• Advice Types in Spring:
52. Page 51Classification: Restricted
Example for Before advice type
public interface EMart{
Chocolate buyChocolate(Customer customer) throws EMartException;
}
public class XYZEMart implements EMart{
public Chocolate buyChocolate(Customer customer) throws
EMartException {
return new Chocolate();}
}
public interface MethodBeforeAdvice {
void before(Method method, Object[] args, Object target) throws
Throwable
}
The parameters are the target method, the arguments passed to the method
and
target object of method invocation.
53. Page 52Classification: Restricted
import org.springframework.aop.MethodBeforeAdvice;
public class WelcomeAdvice implements MethodBeforeAdvice {
public void before(Method method, Object[] args, Object target) {
Customer customer = (Customer) args[0];
System.out.println("Hello " + customer.getName());}
}
Configure the spring configuration file to apply the advice
54. Page 53Classification: Restricted
<beans>
<bean id="EMartTarget“ class=“XYZEMart"/> create proxy target object
<bean id="welcomeAdvice“ class="WelcomeAdvice"/> create advice
<bean id="EMart“tell Spring to create a proxy bean
class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="proxyInterfaces">
<value>EMart</value>implement EMart interface
</property>
<property name="interceptorNames">
<list> apply advice object to incoming calls
<value>welcomeAdvice</value>
</list>
</property>
<property name="target"> use XYZEMart bean as target object
<ref bean=“EMartTarget"/>
</property>
</bean>
</beans>
A bean is loaded whose interface matches EMart. This bean is then tied to the
implementation class XYZEMart
56. Page 55Classification: Restricted
AOP Pointcut
• Tells us where the advice should be applied.
• Spring defines pointcuts in terms of the class and method that is being
advised.
• To determine if a method is eligible for advising we implement the interface:
public interface MethodMatcher
{
boolean matches(Method m, Class targetClass);
public boolean isRuntime();
public boolean matches(Method m, Class target, Object[] args);
}
57. Page 56Classification: Restricted
Spring Advisors
• Most aspects are a combination of advice that defines the aspect’s behavior
and a pointcut defining where the aspect should be executed.
• Spring therefore, offers advisors, which combine advice and pointcuts into
one object.
public interface PointcutAdvisor {
Pointcut getPointcut();
Advice getAdvice();
}
• Most of Spring’s built-in pointcuts also have a corresponding
PointcutAdvisor.
58. Page 57Classification: Restricted
Types of Pointcuts
• Static Pointcuts
• NameMatchedMethodPointcut class has 2 methods:
– public void setMappedName(String)
– public void setMappedNames(String[])
• RegexpMethodPointcut
• Dynamic Pointcuts
• Any Pointcut's implementation with isRuntime() == true
• Built-in dynamic pointcut : ControlFlowPointcut
59. Page 58Classification: Restricted
Example of Static Pointcut
• Setting the mappedName property to set* will match all setter methods.
<bean id="frequentCustomerPointcutAdvisor"
class="org.springframework.aop.support.NameMatchMethodPointcutAdv
isor">
<property name="mappedName">
<value>buy*</value>
</property>
<property name="advice">
<ref bean=“welcomeAdvice"/>
</property>
</bean>…..ProxyFactoryBean
• When our proxy is created, invocations of any method on our target object,
that begins with buy will be advised by our welcomeAdvice.
• This matching only applies to the method name and not the fully qualified
name that includes the class name as well.
61. Page 60Classification: Restricted
Using ProxyFactoryBean
• ProxyFactoryBean creates proxied objects.
• It has properties that control its behavior.
• ProxyFactoryBean properties:
• target: The target bean of the proxy. The object that has to adviced.
• proxyInterfaces: A list of interfaces that must be implemented by the
proxy (beans created by the factory). You can specify single interface
or a list of interfaces.
• interceptorNames: The bean names of the advice to be applied to the
target.
63. Page 62Classification: Restricted
Springs DAO philosophy
• Service objects are accessing the DAOs through interfaces.
• Advantages:
• Easy unit testing of service objects (DAI can be mocked)
• Data Access Interface does not expose what technology it is using to access
data
64. Page 63Classification: Restricted
Spring’s DataAccessException
• Spring’s DAO frameworks do not throw technology-specific exceptions, such
as SQLException or HibernateException.
• All exceptions thrown are subclasses of
org.springframework.dao.DataAccessException.
• DataAccessException is a RuntimeException, so it is an unchecked exception.
Thus the code will not be required to handle these exceptions when they are
thrown by the data access tier.
66. Page 65Classification: Restricted
Working with DataSources
• Getting a DataSource from JNDI:
<bean id="dataSource“
class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>java:comp/env/jdbc/myDatasource</value>
</property>
</bean>
• Spring separates the fixed and variant parts of the data access
process into two distinct classes:
• templates : Templates manage the fixed part of the process like
controlling transactions, managing resources, and handling
exceptions
• Callbacks: Implementations of the callback interfaces define what
is specific to your application—creating statements, binding
parameters
71. Page 70Classification: Restricted
• Create prepared stmt and set the parameters are the only
unique lines of code.
• The rest is a boilerplate code.( Cleaning resources, handling
errors- which is equally important)
• Spring’s JDBC framework will take care of resource
management and handling errors.
• Spring’s data access frameworks incorporate a template
class. In this case, it is the JdbcTemplate class.
Using JDBCTemplate
72. Page 71Classification: Restricted
• To make use of the JdbcTemplate, each of your DAO classes
needs to be configured with a JdbcTemplate instance:
public class StudentDaoJdbc implements StudentDao {
private JdbcTemplate jdbcTemplate;
public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;}
….}
Using JDBCTemplate
73. Page 72Classification: Restricted
Writing Data
• We create a PreparedStatement from a SQL string and then
bind parameters, JdbcTemplate provides an execute(String
sql, Object[] params) method
74. Page 73Classification: Restricted
Spring’s Transaction Manager
• Spring does not directly manage transactions
• It has transaction managers that delegate responsibility for
transaction management to platform-specific transaction
implementation provided by either JTA or persistence mechanism.
76. Page 75Classification: Restricted
Springs ORM framework Support
•Spring provides integration for
•Sun’s standard persistence API JDO,
•as well as the open source ORM frameworks:
•Hibernate
•Apache OJB
•iBATIS SQL Maps
77. Page 76Classification: Restricted
Remoting
• Remoting is a conversation between a client application and
a service.
• The remote application exposes the functionality through a
remote service.
• Spring supports RPC for six different RPC models:
• Remote Method Invocation (RMI)
• Caucho’s Hessian and Burlap
• Spring’s own HTTP invoker
• Enterprise JavaBeans (EJB)
• Web services
80. Page 79Classification: Restricted
Advantages of Spring Remoting
• Regardless of whether you are using RMI, Hessian, Burlap,
HTTP invoker, EJB, or web services, you can wire remote
services into your application as if they were POJOs.
• Spring even catches any RemoteExceptions that are thrown
and rethrows runtime RemoteAccessExceptions in their
place, freeing your code from having to deal with an
exception that it probably can’t recover from
• Spring hides many of the details of remote services, making
them appear as though they are local JavaBeans
82. Page 81Classification: Restricted
Life Cycle of a Request- Spring MVC
Front Controller
Handles request
Maps url Pattern
Request
Logical name of View
Renders Response
Web Browser
83. Page 82Classification: Restricted
A. Dispatcher Servlet
• Must be configured in web.xml
<servlet>
<servlet-name>training</servlet-name> training-servlet.xml
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>training</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
<taglib>
<taglib-uri>/spring</taglib-uri>
<taglib-location>/WEB-INF/spring.tld</taglib-location>
</taglib>
85. Page 84Classification: Restricted
• Configure context loader in web.xml
• A context loader loads context configuration files in addition to the one
that DispatcherServlet loads.
• Two context loaders to choose from:
• ContextLoaderListener
Used when Web Container supports Servlet 2.3 or higher and
initializes servlet listeners before servlets.
• ContextLoaderServlet.
86. Page 85Classification: Restricted
• For ContextLoaderListener
<listener>
<listener-
class>org.springframework.web.context.ContextLoaderListener</listener-
class>
</listener>
• For ContextLoaderServlet
<servlet>
<servlet-name>context</servlet-name>
<servlet-
class>org.springframework.web.context.ContextLoaderServlet</servlet-
class>
<load-on-startup>1</load-on-startup>
</servlet>
• Specify one or more Spring configuration files for the context loader to
load
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/training-service.xml, /WEB-INF/training-data.xml
</param-value>
</context-param>
87. Page 86Classification: Restricted
Spring MVC in a Nutshell
• Minimum steps required to create home page for a Spring training
example.
1.Write the controller class that performs the logic behind the
homepage.
2.Configure the controller in the DispatcherServlet’s context
configuration file (training-servlet.xml).
3.Configure a view resolver to tie the controller to the JSP.
4.Write the JSP that will render the homepage to the user.
88. Page 87Classification: Restricted
Building the Controller
public class HomeController implements Controller {
public ModelAndView handleRequest(HttpServletRequest request,
HttpServletResponse response) throws Exception {
return new ModelAndView("home", "message", greeting);
}
private String greeting;
public void setGreeting(String greeting) {
this.greeting = greeting;}
}
• Similar to struts action but just a simple java bean in application context,
therefore can make use of all the IoC and AOP, for e.g.. Greeting is set
using IoC
89. Page 88Classification: Restricted
Configuring the Controller Bean
• Configure it in the DispatcherServlet’s context configuration
file (which in this case is training-servlet.xml)
<bean name="/home.htm“
class="com.springinaction.training.mvc.HomeController">
<property name="greeting">
<value>Welcome to Spring Training!</value>
</property>
</bean>
90. Page 89Classification: Restricted
Declaring a View Resolver
• Configure it in the DispatcherServlet’s context configuration file (which in
this case is training-servlet.xml)
• In the case of HomeController, we need a view resolver to resolve
“home” to a JSP file that renders the home page.
<bean id="viewResolver" class="org.springframework.web.
servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/jsp/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
91. Page 90Classification: Restricted
Creating the JSP
• Name this JSP “home.jsp” and to place it in the /WEB-INF/jsp folder
within your web application. That’s where InternalResourceViewResolver
will try to find it.
<html>
<head><title>Spring Training, Inc.</title></head>
<body>
<h2>${message}</h2>
</body>
</html>
92. Page 91Classification: Restricted
Quick Recap
1 DispatcherServlet receives a request whose URL pattern is “/home.htm”.
2 DispatcherServlet consults BeanNameUrlHandlerMapping to find a controller
whose bean name is “/home.htm”, finding the HomeController bean.
3 DispatcherServlet dispatches the request to HomeController for processing.
4 HomeController returns a ModelAndView object with a logical view name of
‘home’.
5 DispatcherServlet consults its view resolver (configured as
InternalResourceViewResolver) to find a view whose logical name is home.
Internal-ResourceViewResolver returns the path to /WEB-INF/jsp/home.jsp.
6 DispatcherServlet forwards the request to the JSP at /WEB-INF/jsp/home.jsp to
render the home page to the user.
94. Page 93Classification: Restricted
Handler mapping
• Mapping Requests to Controller
• When associating a request with a specific controller, DispatcherServlet
consults a handler mapping bean.
• Handler mappings typically map a specific controller bean to a URL
pattern
• All of Spring MVC’s handler mappings implement the
org.springframework.web.servlet.HandlerMapping interface.
• Spring has three useful implementations of HandlerMapping
95. Page 94Classification: Restricted
Mapping requests to controllers
• BeanNameUrlHandlerMapping—
• Maps controllers to URLs that are based on the controllers’ bean name.
• This is the default handler.
<bean name="/home.htm“
class="com.springinaction.training.mvc.HomeController"></bean>
• SimpleUrlHandlerMapping—
• Maps controllers to URLs using a property collection defined in the
context configuration file
• CommonsPathMapHandlerMapping—
• Maps controllers to URLs using source level metadata placed in the
controller code.
• Example
/**
* @@org.springframework.web.servlet.handler.
commonsattributes.PathMap("/displayCourse.htm")
*/
public class DisplayCourseController extends
AbstractCommandController {…}
99. Page 98Classification: Restricted
Examples
• Simple Controller:
• When you need to take no(or few parameters) e.g.. When you wish to
display the list of all courses.
• Command Controllers:
• For e.g. after viewing a list of available courses, you may want to view
more details about that course.
• This controller will automatically bind parameters to a command
object and provide hooks for you to plug in validators to ensure that
the parameters are valid.
101. Page 100Classification: Restricted
Processing Form Submission
E.g. Student registration
Form Controllers add functionality to display a form when
an HTTP GET request is received and process the form
when an HTTP POST is received
If any errors occur in processing the form, the controller
will know to redisplay the form so that the user can
correct the errors and resubmit
103. Page 102Classification: Restricted
• doSubmitAction() method handles the form submission (an HTTP POST request) by passing
the command object (which happens to be a Student domain object) to enrollStudent()
• But it is not clear, how registration form is displayed & what is return view
<bean id="registerStudentController" class="com.springinaction.
training.mvc.RegisterStudentController">
<property name="studentService">
<ref bean="studentService"/>
</property>
<property name="formView">
<value>newStudentForm</value>
</property>
<property name="successView">
<value>studentWelcome</value>
</property>
</bean>
104. Page 103Classification: Restricted
• Disadv of doSubmitAction(): cannot return a model and view object. E.g..
When you wish to display the details of students after successful
registration.
• Use onSubmit()
protected ModelAndView onSubmit(Object command, BindException
errors) throws Exception {
Student student = (Student) command;
studentService.enrollStudent(student);
return new ModelAndView(getSuccessView(),"student", student); }
105. Page 104Classification: Restricted
Validating Form Input
• The org.springframework.validation.Validator interface accommodates
validation for Spring MVC.
public interface Validator {
void validate(Object obj, Errors errors);
boolean supports(Class clazz);
}
• Examines the fields of the object passed into the validate() method and
reject any invalid values via the Errors object.
• supports() method is used to help Spring determine whether or not the
validator can be used for a given class.
106. Page 105Classification: Restricted
public class StudentValidator implements Validator {
public boolean supports(Class clazz) {
return clazz.equals(Student.class);}
public void validate(Object command, Errors errors) {
Student student = (Student) command;
ValidationUtils.rejectIfEmpty( errors, "login",
"required.login","Login is required");
ValidationUtils.rejectIfEmpty( errors, "password",
"required.password", "Password is required"); ….}}
<bean id="registerStudentController"
class="com.springinaction.training.mvc.RegisterStudentController">
……
<property name="validator">
<bean class="com.springinaction.training.mvc.StudentValidator"/>
</property>
</bean>
107. Page 106Classification: Restricted
Resolving Views
• In Spring MVC, a view is a bean that renders results to the user.
• Rendering depends on the type of view used: J
• JSP, Pdf, Excel sheet, Velocity and FreeMarker templates.
• View Resolvers are used to resolve the logical view to a View Bean
• Internal available resolvers:
• InternalResourceViewResolver
• BeanNameViewResolver
• ResourceBundleViewResolver
• XmlViewResolver
109. Page 108Classification: Restricted
Working with Jakarta-Struts
• Consider how would you retrieve list of all courses in Struts.
public class ListCourseAction extends Action {
private CourseService courseService;
public ActionForward execute( ActionMapping mapping,
ActionForm form,
HttpServletRequest request, HttpServletResponse
response) throws Exception {
Set allCourses = courseService.getAllCourses();
request.setAttribute("courses", allCourses);
return mapping.findForward("courseList");
}
}
110. Page 109Classification: Restricted
Spring offers 2 types of Struts Integration
• Implementing Spring-aware Struts actions
• Delegating requests to Struts actions that are managed as Spring
beans
Before that:
• Register a Struts plug-in in struts-config.xml, that is aware of the Spring
application context
<plug-in
className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation"
value="/WEB-INF/training-servlet.xml,/WEB-INF/…"/>
</plug-in>
• ContextLoaderPlugIn loads a Spring application context (a
WebApplication-Context, to be specific) using the context configuration
files listed (comma separated) in its contextConfigLocation property.
111. Page 110Classification: Restricted
Implementing Spring-aware Struts actions
• Write all of your Struts action classes to extend a common base
class that has access to the Spring application context.
OR
• Spring comes with
org.springframework.web.struts.ActionSupport, an abstract
implementation of the org.apache.struts.action.Action
• It overrides the setServlet() method to retrieve the
WebApplicationContext from the Context-LoaderPlugIn
• Anytime your action needs to access a bean from the Spring
context, it just needs to call the getBean() method.
113. Page 112Classification: Restricted
Disadvantages of Spring aware struts type:
• Action class directly uses Spring specific classes. This
tightly couples struts action code with spring
• The action class is responsible for looking up references to
Spring-managed beans. This is in direct opposition to the
notion of inversion of control (IoC)
114. Page 113Classification: Restricted
Delegating requests to Struts actions that are managed as Spring beans
• In the struts-config.xml write a proxy action.
• The proxy action will
• retrieve the application context from the ContextLoaderPlugIn
• look up the real Struts action from the spring context
• then delegate responsibility to the real Struts action.
• Spring provides org.springframework.web.struts.DelegatingActionProxy
class.
<action path="/listCourses"
type="org.springframework.web.struts.DelegatingActionProxy"/>
116. Page 115Classification: Restricted
• You don’t need to register ListCourseAction in struts-
config.xml. Instead, you register it as a bean in your Spring
context configuration file:
<bean name="/listCourses"
class="com.springinaction.training.struts.ListCourseActi
on">
<property name="courseService">
<ref bean="courseService"/>
</property>
</bean>
• Value of the name attribute must exactly match the path
attribute of the <action> in struts-config.xml.
• Adv: Spring is just another bean now and you can use
Spring’s IoC to wire service beans into the Struts action.
118. Page 117Classification: Restricted
Spring Security (Acegi security) Features
• Single Sign on
• Reuses your Spring expertise: Spring application contexts
for all configuration
• Provide a comprehensive ACL(Access Control list) package
• Keeps your objects free of security code
• http://acegisecurity.org/index.html
119. Page 118Classification: Restricted
Spring and Integration
• Spring is essentially an integration platform
•Aims to provide a POJO model in whatever environment,
with whatever services
• Minimal system requirements
•Spring runs in Java 1.3 and above
•Takes advantage of 1.4 and 5.0 features if available
• Spring offers portability between different environments
• Integrates with a large number of products
•Quartz scheduler
•Velocity template engine
•Jasper reports etc
120. Page 119Classification: Restricted
Spring in a J2EE Environment
• Does not violate J2EE programming restrictions
• Provides services on any J2EE application server
•Runs well on current, stable servers such as WebSphere
4.0–6.0 and WebLogic 6.1-9.0
• Although Spring is an alternative to EJB in many cases, it
provides services for invoking and implementing EJBs
•Codeless EJB proxies, exposing a POJO interface
•Implementing EJBs that internally use Spring
121. Page 120Classification: Restricted
Momentum Around Spring
• Books:
• Pro Spring (Rod Harrop)
• J2EE without EJB (Rod Johnson, Juergen Hoeller)
• Spring In Action(Craig Walls, Ryan Breidenbach)
• Java Development with the Spring Framework (Rod
Johnson et al.)
• Expert One-on-One: J2EE Design and Development (Rod
Johnson)
• Websites:
• www.springframework.org
• www.springhub.com
• http://martinfowler.com/articles/injection.html
• http://www.roseindia.net/spring/index.shtml
122. Page 121Classification: Restricted
Who’s using Spring?
Spring is widely used in many industries, including…
• Banking: HSBC Investment Bank, DekaBank, BNP Paribas, BBS, CSFB (New
York), Goldman Sachs, JP Morgan (Bank One)
• Transactional Web applications, message-driven middleware
• Retail and investment banking
• Scientific research
• Defence(Norwegian military)
• A growing number of Fortune 500 companies
• High volume Web sites
• Significant enterprise usage, not merely adventurous early adopters