forked from spring-projects/spring-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
new-in-3.0.xml
522 lines (416 loc) · 18.9 KB
/
new-in-3.0.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
<?xml version="1.0" encoding="UTF-8"?>
<chapter xml:id="new-in-3.0"
xmlns="http://docbook.org/ns/docbook" version="5.0"
xmlns:xl="http://www.w3.org/1999/xlink"
xmlns:xi="http://www.w3.org/2001/XInclude"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://docbook.org/ns/docbook http://www.docbook.org/xml/5.0/xsd/docbook.xsd
http://www.w3.org/1999/xlink http://www.docbook.org/xml/5.0/xsd/xlink.xsd">
<title>New Features and Enhancements in Spring Framework 3.0</title>
<para>If you have been using the Spring Framework for some time, you will be
aware that Spring has undergone two major revisions: Spring 2.0, released in
October 2006, and Spring 2.5, released in November 2007. It is now time for
a third overhaul resulting in Spring Framework 3.0.</para>
<sidebar xml:id="new-in-3.0-intro-java">
<title>Java SE and Java EE Support</title>
<para>The Spring Framework is now based on Java 5, and Java 6 is fully
supported.</para>
<para>Furthermore, Spring is compatible with J2EE 1.4 and Java EE 5, while
at the same time introducing some early support for Java EE 6.</para>
</sidebar>
<section xml:id="new-in-3.0-intro">
<title>Java 5</title>
<para>The entire framework code has been revised to take advantage of Java
5 features like generics, varargs and other language improvements. We have
done our best to still keep the code backwards compatible. We now have
consistent use of generic Collections and Maps, consistent use of generic
FactoryBeans, and also consistent resolution of bridge methods in the
Spring AOP API. Generic ApplicationListeners automatically receive
specific event types only. All callback interfaces such as
TransactionCallback and HibernateCallback declare a generic result value
now. Overall, the Spring core codebase is now freshly revised and
optimized for Java 5.</para>
<para>Spring's TaskExecutor abstraction has been updated for close
integration with Java 5's java.util.concurrent facilities. We provide
first-class support for Callables and Futures now, as well as
ExecutorService adapters, ThreadFactory integration, etc. This has been
aligned with JSR-236 (Concurrency Utilities for Java EE 6) as far as
possible. Furthermore, we provide support for asynchronous method
invocations through the use of the new @Async annotation (or EJB 3.1's
@Asynchronous annotation).</para>
</section>
<section xml:id="new-in-3.0-improved-docs">
<title>Improved documentation</title>
<para>The Spring reference documentation has also substantially been
updated to reflect all of the changes and new features for Spring Framework
3.0. While every effort has been made to ensure that there are no errors in
this documentation, some errors may nevertheless have crept in. If you do
spot any typos or even more serious errors, and you can spare a few cycles
during lunch, please do bring the error to the attention of the Spring
team by <link xl:href="http://jira.springframework.org/">raising an
issue</link>.</para>
</section>
<section xml:id="new-in-3.0-new-tutorial">
<title>New articles and tutorials</title>
<para>
There are many excellent articles and tutorials that show how to get
started with Spring Framework 3 features. Read them at the
<link xl:href="http://www.springsource.org/documentation">Spring Documentation</link> page.
</para>
<para xml:id="new-in-3.0-samples">
The samples have been improved and updated to take advantage of the new features in Spring
Framework 3. Additionally, the samples have been moved out of the source tree into a dedicated SVN
<link xl:href="https://anonsvn.springframework.org/svn/spring-samples/">repository</link> available at:</para>
<para>
<literal>https://anonsvn.springframework.org/svn/spring-samples/</literal>
</para>
<para>As such, the samples are no longer distributed alongside Spring
Framework 3 and need to be downloaded separately from the repository
mentioned above. However, this documentation will continue to refer to
some samples (in particular Petclinic) to illustrate various features.</para>
<note><para>For more information on Subversion (or in short SVN), see the project homepage at:
<literal>http://subversion.apache.org/</literal></para>
</note>
</section>
<section xml:id="new-in-3.0-modules-build">
<title>New module organization and build system</title>
<para>The framework modules have been revised and are now managed
separately with one source-tree per module jar:</para>
<itemizedlist>
<listitem>
<para>org.springframework.aop</para>
</listitem>
<listitem>
<para>org.springframework.beans</para>
</listitem>
<listitem>
<para>org.springframework.context</para>
</listitem>
<listitem>
<para>org.springframework.context.support</para>
</listitem>
<listitem>
<para>org.springframework.expression</para>
</listitem>
<listitem>
<para>org.springframework.instrument</para>
</listitem>
<listitem>
<para>org.springframework.jdbc</para>
</listitem>
<listitem>
<para>org.springframework.jms</para>
</listitem>
<listitem>
<para>org.springframework.orm</para>
</listitem>
<listitem>
<para>org.springframework.oxm</para>
</listitem>
<listitem>
<para>org.springframework.test</para>
</listitem>
<listitem>
<para>org.springframework.transaction</para>
</listitem>
<listitem>
<para>org.springframework.web</para>
</listitem>
<listitem>
<para>org.springframework.web.portlet</para>
</listitem>
<listitem>
<para>org.springframework.web.servlet</para>
</listitem>
<listitem>
<para>org.springframework.web.struts</para>
</listitem>
</itemizedlist>
<sidebar xml:id="new-in-3.0-intro-spring-jar">
<title>Note:</title>
<para>The spring.jar artifact that contained almost the entire framework
is no longer provided.</para>
</sidebar>
<para>We are now using a new Spring build system as known from Spring Web
Flow 2.0. This gives us:</para>
<itemizedlist>
<listitem>
<para>Ivy-based "Spring Build" system</para>
</listitem>
<listitem>
<para>consistent deployment procedure</para>
</listitem>
<listitem>
<para>consistent dependency management</para>
</listitem>
<listitem>
<para>consistent generation of OSGi manifests</para>
</listitem>
</itemizedlist>
</section>
<section xml:id="new-in-3.0-features-overview">
<title>Overview of new features</title>
<para>This is a list of new features for Spring Framework 3.0. We will cover these
features in more detail later in this section.</para>
<itemizedlist>
<listitem>
<para>Spring Expression Language</para>
</listitem>
<listitem>
<para>IoC enhancements/Java based bean metadata</para>
</listitem>
<listitem>
<para>General-purpose type conversion system and field formatting
system</para>
</listitem>
<listitem>
<para>Object to XML mapping functionality (OXM) moved from Spring Web
Services project</para>
</listitem>
<listitem>
<para>Comprehensive REST support</para>
</listitem>
<listitem>
<para>@MVC additions</para>
</listitem>
<listitem>
<para>Declarative model validation</para>
</listitem>
<listitem>
<para>Early support for Java EE 6</para>
</listitem>
<listitem>
<para>Embedded database support</para>
</listitem>
</itemizedlist>
<section xml:id="new-feature-java5">
<title>Core APIs updated for Java 5</title>
<para>BeanFactory interface returns typed bean instances as far as
possible: <itemizedlist>
<listitem>
<para>T getBean(Class<T> requiredType)</para>
</listitem>
<listitem>
<para>T getBean(String name, Class<T> requiredType)</para>
</listitem>
<listitem>
<para>Map<String, T> getBeansOfType(Class<T>
type)</para>
</listitem>
</itemizedlist></para>
<para>Spring's TaskExecutor interface now extends
<classname>java.util.concurrent.Executor</classname>: <itemizedlist>
<listitem>
<para>extended AsyncTaskExecutor supports standard Callables with
Futures</para>
</listitem>
</itemizedlist></para>
<para>New Java 5 based converter API and SPI: <itemizedlist>
<listitem>
<para>stateless ConversionService and Converters</para>
</listitem>
<listitem>
<para>superseding standard JDK PropertyEditors</para>
</listitem>
</itemizedlist></para>
<para>Typed ApplicationListener<E></para>
</section>
<section xml:id="new-feature-el">
<title>Spring Expression Language</title>
<para>Spring introduces an expression language which is similar to
Unified EL in its syntax but offers significantly more features. The
expression language can be used when defining XML and Annotation based
bean definitions and also serves as the foundation for expression
language support across the Spring portfolio. Details of this new
functionality can be found in the chapter <link
linkend="expressions">Spring Expression Language (SpEL).</link></para>
<para>The Spring Expression Language was created to provide the Spring
community a single, well supported expression language that can be used
across all the products in the Spring portfolio. Its language features
are driven by the requirements of the projects in the Spring portfolio,
including tooling requirements for code completion support within the
Eclipse based <link xl:href="http://www.springsource.com/products/sts">SpringSource
Tool Suite</link>.</para>
<para>The following is an example of how the Expression Language can be
used to configure some properties of a database setup <programlisting
language="xml"><bean class="mycompany.RewardsTestDatabase">
<property name="databaseName"
value="#{systemProperties.databaseName}"/>
<property name="keyGenerator"
value="#{strategyBean.databaseKeyGenerator}"/>
</bean>
</programlisting></para>
<para>This functionality is also available if you prefer to configure
your components using annotations: <programlisting language="java">@Repository
public class RewardsTestDatabase {
@Value("#{systemProperties.databaseName}")
public void setDatabaseName(String dbName) { … }
@Value("#{strategyBean.databaseKeyGenerator}")
public void setKeyGenerator(KeyGenerator kg) { … }
}
</programlisting></para>
</section>
<section xml:id="new-feature-java-config">
<title>The Inversion of Control (IoC) container</title>
<section xml:id="new-java-configuration">
<title>Java based bean metadata</title>
<para>Some core features from the <link
xl:href="http://www.springsource.org/javaconfig">JavaConfig</link>
project have been added to the Spring Framework now. This means that
the following annotations are now directly supported: <itemizedlist>
<listitem>
<para>@Configuration</para>
</listitem>
<listitem>
<para>@Bean</para>
</listitem>
<listitem>
<para>@DependsOn</para>
</listitem>
<listitem>
<para>@Primary</para>
</listitem>
<listitem>
<para>@Lazy</para>
</listitem>
<listitem>
<para>@Import</para>
</listitem>
<listitem>
<para>@ImportResource</para>
</listitem>
<listitem>
<para>@Value</para>
</listitem>
</itemizedlist></para>
<para>Here is an example of a Java class providing basic configuration
using the new JavaConfig features: <programlisting language="java">package org.example.config;
@Configuration
public class AppConfig {
private @Value("#{jdbcProperties.url}") String jdbcUrl;
private @Value("#{jdbcProperties.username}") String username;
private @Value("#{jdbcProperties.password}") String password;
@Bean
public FooService fooService() {
return new FooServiceImpl(fooRepository());
}
@Bean
public FooRepository fooRepository() {
return new HibernateFooRepository(sessionFactory());
}
@Bean
public SessionFactory sessionFactory() {
// wire up a session factory
AnnotationSessionFactoryBean asFactoryBean =
new AnnotationSessionFactoryBean();
asFactoryBean.setDataSource(dataSource());
// additional config
return asFactoryBean.getObject();
}
@Bean
public DataSource dataSource() {
return new DriverManagerDataSource(jdbcUrl, username, password);
}
}
</programlisting> To get this to work you need to add the following component
scanning entry in your minimal application context XML file.
<programlisting language="xml"><context:component-scan base-package="org.example.config"/>
<util:properties id="jdbcProperties" location="classpath:org/example/config/jdbc.properties"/>
</programlisting>
Or you can bootstrap a <literal>@Configuration</literal> class directly using
<literal>AnnotationConfigApplicationContext</literal>:
<programlisting language="java">public static void main(String[] args) {
ApplicationContext ctx = new AnnotationConfigApplicationContext(AppConfig.class);
FooService fooService = ctx.getBean(FooService.class);
fooService.doStuff();
}</programlisting>
See <xref linkend="beans-java-instantiating-container"/> for full information on
<literal>AnnotationConfigApplicationContext</literal>.</para>
</section>
<section xml:id="new-bean-metadata-in-components">
<title>Defining bean metadata within components</title>
<para><literal>@Bean</literal> annotated methods are also supported
inside Spring components. They contribute a factory bean definition to
the container. See <link
linkend="beans-factorybeans-annotations">Defining bean metadata within
components</link> for more information</para>
</section>
</section>
<section xml:id="new-feature-convert-and-format">
<title>General purpose type conversion system and field formatting
system</title>
<para>A general purpose <link linkend="core-convert">type conversion
system</link> has been introduced. The system is currently used by SpEL
for type conversion, and may also be used by a Spring Container and DataBinder when
binding bean property values.</para>
<para>In addition, a <link linkend="format">formatter</link> SPI
has been introduced for formatting field values. This SPI provides
a simpler and more robust alternative to JavaBean PropertyEditors for use in client
environments such as Spring MVC.</para>
</section>
<section xml:id="new-feature-oxm">
<title>The Data Tier</title>
<para>Object to XML mapping functionality (OXM) from the Spring Web
Services project has been moved to the core Spring Framework now. The
functionality is found in the <literal>org.springframework.oxm</literal>
package. More information on the use of the <literal>OXM</literal>
module can be found in the <link linkend="oxm">Marshalling XML using O/X
Mappers</link> chapter.</para>
</section>
<section xml:id="new-feature-rest">
<title>The Web Tier</title>
<para>The most exciting new feature for the Web Tier is the support for
building RESTful web services and web applications. There are also some
new annotations that can be used in any web application.</para>
<section xml:id="new-feature-rest-support">
<title>Comprehensive REST support</title>
<para>Server-side support for building RESTful applications has been
provided as an extension of the existing annotation driven MVC web
framework. Client-side support is provided by the
<classname>RestTemplate</classname> class in the spirit of other
template classes such as <classname>JdbcTemplate</classname> and
<classname>JmsTemplate</classname>. Both server and client side REST
functionality make use of
<interfacename>HttpConverter</interfacename>s to facilitate the
conversion between objects and their representation in HTTP requests
and responses.</para>
<para>The <classname>MarshallingHttpMessageConverter</classname> uses
the <emphasis>Object to XML mapping</emphasis> functionality mentioned
earlier.</para>
<para>Refer to the sections on <link linkend="mvc">MVC</link> and <link
linkend="rest-resttemplate">the RestTemplate</link> for more
information.</para>
</section>
<section xml:id="new-feature-at-mvc">
<title>@MVC additions</title>
<para>A <literal>mvc</literal> namespace has been introduced that greatly simplifies Spring MVC configuration.</para>
<para>Additional annotations such as
<classname>@CookieValue</classname> and
<classname>@RequestHeaders</classname> have been added. See <link
linkend="mvc-ann-cookievalue">Mapping cookie values with the
@CookieValue annotation</link> and <link
linkend="mvc-ann-requestheader">Mapping request header attributes with
the @RequestHeader annotation</link> for more information.</para>
</section>
</section>
<section xml:id="new-feature-validation">
<title>Declarative model validation</title>
<para>Several <link linkend="validation-beanvalidation">validation enhancements</link>,
including JSR 303 support that uses Hibernate Validator as the default provider.</para>
</section>
<section xml:id="new-feature-jee-6">
<title>Early support for Java EE 6</title>
<para>We provide support for asynchronous method invocations through the
use of the new @Async annotation (or EJB 3.1's @Asynchronous
annotation).</para>
<para>JSR 303, JSF 2.0, JPA 2.0, etc</para>
</section>
<section xml:id="new-feature-embedded-databases">
<title>Support for embedded databases</title>
<para>Convenient support for <link
linkend="jdbc-embedded-database-support">embedded Java database
engines</link>, including HSQL, H2, and Derby, is now provided.</para>
</section>
</section>
</chapter>