The Spring Framework for Java and .NET

helpflightInternet και Εφαρμογές Web

10 Νοε 2013 (πριν από 3 χρόνια και 7 μήνες)

83 εμφανίσεις

Dirk Burkholz

My project

Overview & Motivation

Core principles and techniques

Spotlight on one technique

Further features

Conclusion
14.01.2009
2
Dirk Burkholz
-
The Spring Framework
for Java and .NET

GLOBUS group, hypermarkets

Spring for Java in use for several
J2EE projects

Launch of software
-
aided business process
management based on .NET

Project: Evaluation if the knowledge and
experience about Spring for Java can easily be
transferred to projects in C#.NET using
Spring.NET

Sample project using some core features of Spring
14.01.2009
3
Dirk Burkholz
-
The Spring Framework
for Java and .NET

Core Principles

Inversion of Control (
IoC
)

Dependency Injection (DI)

Aspect Oriented Programming (AOP)

Further features

Template
-
based database access (DAO support)

Webservices


14.01.2009
4
Dirk Burkholz
-
The Spring Framework
for Java and .NET

Rod Johnson, J2EE consultant, found some
drawbacks in J2EE design

He collected best practices to avoid this
drawbacks in his book „Expert One
-
on
-
one
J2EE Design and Development“ in 2002; a very
basic framework was already included

Now: Spring Framework for Java 2.5 in 2007

Mark Pollack‘s first .NET port in 2003

Now: Spring.NET 1.2 in 2008
14.01.2009
5
Dirk Burkholz
-
The Spring Framework
for Java and .NET

Responsibility to
instatiate
new objects not by
the using object but by the
IoC
container

Coding against interfaces and
superclasses
, not
implementations

Uses Dependency Injection

XML
-
based context describing managed
objects, their properties and dependencies to
other managed objects
14.01.2009
6
Dirk Burkholz
-
The Spring Framework
for Java and .NET
<
bean
id
=„student1“
class
=„Student“>
<
property
name
=„
studentid

value
=„42“ />

</
bean
>

<
bean
id
=„university0“
class
=„University“>
<
property
name
=„
bestStudent

ref
=„student1“ />

</
bean
>
14.01.2009
7
Dirk Burkholz
-
The Spring Framework
for Java and .NET

Injecting dependencies of managed objects by
the
IoC
container instead of
instatiating
dependent objects by
new
ObjectType
()

Spring uses

Setter Injection: matching properties by name

String property
xy

setXy
(String s)

Constructor Injection: matching
constructur
arguments by order and type

Object
obj
,
int
argument
i

new
obj
(
i
)
14.01.2009
8
Dirk Burkholz
-
The Spring Framework
for Java and .NET

Crosscutting concerns
are requirements
orthogonal to the software design/
decomposition, e.g. logging

Joinpoints
are points in the program flow,
Pointcuts
select a subset of them

Advices
add the desired functionality at the
joinpoints
selected by
pointcuts

Spring supports Before
-
, Around
-
, After
-
,
AfterException
and
AfterReturning
Advices
14.01.2009
9
Dirk Burkholz
-
The Spring Framework
for Java and .NET

Drawbacks to classic AOP (e.g. AspectJ)

Advising managed objects only

Advising public methods only

No advices for advised methods

Advices are singletons

Access to method invocation: arguments,
return value, thrown exception

Possibility to check, change or omit return values
14.01.2009
10
Dirk Burkholz
-
The Spring Framework
for Java and .NET
SPRING JAVA
SPRING.NET

AspectJ
-
like

J2SE dynamic proxies to
advice interfaces

CGlib2 proxies to
advice classes

Annotation
-
based
syntax possible

Full advising of
interfaces only

Advising virtual
methods of classes only
14.01.2009
11
Dirk Burkholz
-
The Spring Framework
for Java and .NET

Central concept: Template

Capsules and manages connection to data source

Provides methods mapping result sets to more
generic collections/types

Provides many helper methods

Translates vendor
-
specific exceptions to Spring‘s
generic
DataAccessException
hierarchy (using
SQLExceptionTranslator
)
14.01.2009
12
Dirk Burkholz
-
The Spring Framework
for Java and .NET
SPRING JAVA
SPRING.NET

DataSource

JdbcTemplate

Mapping
to
Map
/List
queryForMap
()/List

Statement
parameters
by
object
array

queryForObject
()
and
specialized
methods

DbProvider

AdoTemplate

Mapping
to
DataSet
DataSetCreateWithParams
()

Statement
parameters
by
IDbParameters

ExecuteScalar
()
only
14.01.2009
13
Dirk Burkholz
-
The Spring Framework
for Java and .NET

Goal:
Webservice
support easier than with
J2EE/ASP.NET

Using
webservice
proxies

Testing scenario:

Cut between
DataProvider
and Factory

Connections via
webservice

Java

Java

.NET

.NET

Java
-
.NET

.NET

Java
14.01.2009
14
Dirk Burkholz
-
The Spring Framework
for Java and .NET

Core principles are the same except for Java/.NET
core technology differences

Spring for Java developers can easily apply their
knowledge when developing Spring.NET applications

Some differences in details, especially naming

Developers can easily overcome this by using code
completion and looking up the reference’s section
Spring.NET
for
Java
developers

Spring for Java has more features than Spring.NET

Core features are already well supported, so certain
features are only missing for special cases

More features: Web MVC, Security, Validation, …
14.01.2009
15
Dirk Burkholz
-
The Spring Framework
for Java and .NET

The Spring Framework
-
Reference
Documentation:
http://static.springframework.org/spring/docs/2
.5.x/reference/index.html

The Spring.NET Framework

Reference
Documentation:
http://www.springframework.net/docs/1.2.0/ref
erence/html/index.html

Rod Johnson. Expert One
-
on
-
one J2EE Design and
Development (Programmer to Programmer).
Wiley & Sons 2003. ISBN:
978
-
0764543852
14.01.2009
16
Dirk Burkholz
-
The Spring Framework
for Java and .NET