2009-03-19 04:00:49 +08:00
|
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
2009-04-07 00:12:50 +08:00
|
|
|
<chapter id="new-in-3">
|
2009-03-19 04:00:49 +08:00
|
|
|
<title>What's new in Spring 3.0?</title>
|
|
|
|
|
|
2009-04-03 12:08:08 +08:00
|
|
|
<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 3.0.</para>
|
2009-03-19 04:00:49 +08:00
|
|
|
|
2009-04-03 12:08:08 +08:00
|
|
|
<sidebar id="new-in-3-intro-java">
|
|
|
|
|
<title>Java SE and Java EE Support</title>
|
2009-03-19 04:00:49 +08:00
|
|
|
|
2009-04-03 12:08:08 +08:00
|
|
|
<para>The Spring Framework is now based on Java 5 and Java 6 is fully
|
|
|
|
|
supported.</para>
|
2009-03-19 04:00:49 +08:00
|
|
|
|
2009-04-03 12:08:08 +08:00
|
|
|
<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>
|
2009-03-19 04:00:49 +08:00
|
|
|
|
2009-04-03 12:08:08 +08:00
|
|
|
<section id="new-in-3-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
|
|
|
|
|
generified FactoryBeans, and also consistent resolution of bridge methods
|
|
|
|
|
in the Spring AOP API. Generified 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>
|
2009-03-19 04:00:49 +08:00
|
|
|
</section>
|
|
|
|
|
|
2009-04-01 11:35:39 +08:00
|
|
|
<section id="new-in-3-improved-docs">
|
2009-03-19 04:00:49 +08:00
|
|
|
<title>Improved documentation</title>
|
|
|
|
|
|
2009-04-01 11:35:39 +08:00
|
|
|
<sidebar id="new-in-3-intro-work-in-progress">
|
|
|
|
|
<title>Note:</title>
|
|
|
|
|
|
|
|
|
|
<para>The current documentation is a <emphasis>*** WORK IN PROGRESS
|
|
|
|
|
***</emphasis> and is currently being re-written to reflect all the
|
|
|
|
|
changes in the framework and from now relying on Java 5 features.</para>
|
|
|
|
|
</sidebar>
|
|
|
|
|
|
2009-03-19 04:00:49 +08:00
|
|
|
<para>The Spring reference documentation has also substantially been
|
2009-04-01 11:35:39 +08:00
|
|
|
updated to reflect all of the changes and new features for Spring 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
|
2009-03-19 04:00:49 +08:00
|
|
|
during lunch, please do bring the error to the attention of the Spring
|
2009-04-01 11:35:39 +08:00
|
|
|
team by <ulink url="http://jira.springframework.org/">raising an
|
2009-03-19 04:00:49 +08:00
|
|
|
issue</ulink>.</para>
|
2009-04-01 11:35:39 +08:00
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
<section id="new-in-3-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>
|
|
|
|
|
</itemizedlist>
|
|
|
|
|
|
|
|
|
|
<sidebar id="new-in-3-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>
|
2009-03-19 04:00:49 +08:00
|
|
|
|
2009-04-01 11:35:39 +08:00
|
|
|
<listitem>
|
|
|
|
|
<para>consistent dependency management</para>
|
|
|
|
|
</listitem>
|
|
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
|
<para>consistent generation of OSGi manifests</para>
|
|
|
|
|
</listitem>
|
|
|
|
|
</itemizedlist>
|
2009-03-19 04:00:49 +08:00
|
|
|
</section>
|
|
|
|
|
|
2009-04-01 11:35:39 +08:00
|
|
|
<section id="new-in-3-features-overview">
|
|
|
|
|
<title>Overview of new features</title>
|
|
|
|
|
|
|
|
|
|
<para>This is a list of new features for Spring 3.0. We will cover these
|
2009-04-14 12:43:15 +08:00
|
|
|
features in more detail later in this section.</para>
|
2009-04-01 11:35:39 +08:00
|
|
|
|
|
|
|
|
<itemizedlist>
|
|
|
|
|
<listitem>
|
|
|
|
|
<para>Spring Expression Language</para>
|
|
|
|
|
</listitem>
|
|
|
|
|
|
|
|
|
|
<listitem>
|
2009-04-14 14:59:22 +08:00
|
|
|
<para>IoC enhancements/Java based bean metadata</para>
|
2009-04-01 11:35:39 +08:00
|
|
|
</listitem>
|
|
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
|
<para>Comprehensive REST support</para>
|
2009-04-08 22:06:01 +08:00
|
|
|
</listitem>
|
2009-04-01 11:35:39 +08:00
|
|
|
|
2009-04-08 22:06:01 +08:00
|
|
|
<listitem>
|
|
|
|
|
<para>@MVC additions</para>
|
2009-04-01 11:35:39 +08:00
|
|
|
</listitem>
|
|
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
|
<para>Declarative model validation</para>
|
|
|
|
|
</listitem>
|
|
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
|
<para>Early support for Java EE 6</para>
|
|
|
|
|
</listitem>
|
|
|
|
|
</itemizedlist>
|
2009-04-03 12:08:08 +08:00
|
|
|
|
2009-04-14 14:59:22 +08:00
|
|
|
<section id="new-feature-java5">
|
|
|
|
|
<title>Core APIs updated for Java 5</title>
|
|
|
|
|
|
|
|
|
|
<para>BeanFactoryinterface returns typed bean instancesas far as
|
|
|
|
|
possible <itemizedlist>
|
|
|
|
|
<listitem>
|
|
|
|
|
<para>T getBean(Stringname, Class<T> requiredType)</para>
|
|
|
|
|
</listitem>
|
|
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
|
<para>Map<String, T> getBeansOfType(Class<T>
|
|
|
|
|
type)</para>
|
|
|
|
|
</listitem>
|
|
|
|
|
</itemizedlist></para>
|
|
|
|
|
|
|
|
|
|
<para>Spring's TaskExecutorinterface extends
|
|
|
|
|
<classname>java.util.concurrent.Executor</classname> now <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>
|
2009-04-14 12:02:10 +08:00
|
|
|
|
2009-04-14 14:59:22 +08:00
|
|
|
<section 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 with a single well supported expression language that can 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 SpringSource Tool Suite.</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
|
2009-04-14 12:43:15 +08:00
|
|
|
public class RewardsTestDatabase {
|
|
|
|
|
|
|
|
|
|
@Value("#{systemProperties.databaseName}")
|
|
|
|
|
public void setDatabaseName(String dbName) { … }
|
|
|
|
|
|
|
|
|
|
@Value("#{strategyBean.databaseKeyGenerator}")
|
|
|
|
|
public voidsetKeyGenerator(KeyGenerator kg) { … }
|
|
|
|
|
}
|
2009-04-14 14:59:22 +08:00
|
|
|
</programlisting></para>
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
<section id="new-feature-java-config">
|
|
|
|
|
<title>The Inversion of Control (IoC) container</title>
|
|
|
|
|
|
|
|
|
|
<section id="new-java-configuration">
|
|
|
|
|
<title>Java based bean metadata</title>
|
|
|
|
|
|
|
|
|
|
<para>Some core features from the <ulink
|
|
|
|
|
url="http://www.springsource.org/javaconfig"><link
|
|
|
|
|
linkend="???">JavaConfig</link></ulink> 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>
|
2009-04-03 12:08:08 +08:00
|
|
|
|
2009-04-14 14:59:22 +08:00
|
|
|
<listitem>
|
|
|
|
|
<para>@Bean</para>
|
|
|
|
|
</listitem>
|
|
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
|
<para>@Primary</para>
|
|
|
|
|
</listitem>
|
|
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
|
<para>@Lazy</para>
|
|
|
|
|
</listitem>
|
|
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
|
<para>@Import</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">@Configuration
|
2009-04-14 12:43:15 +08:00
|
|
|
public class AppConfig{
|
|
|
|
|
@Value("#{jdbcProperties.url}") String jdbcUrl;
|
|
|
|
|
@Value("#{jdbcProperties.username}") String username;
|
|
|
|
|
@Value("#{jdbcProperties.password}") String password;
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
|
public FooServicefooService() {
|
|
|
|
|
return new FooServiceImpl(fooRepository());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
|
public FooRepositoryfooRepository() {
|
|
|
|
|
return new HibernateFooRepository(sessionFactory());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
|
public SessionFactorysessionFactory() {
|
|
|
|
|
// wire up a session factory using
|
|
|
|
|
// AnnotationSessionFactoryBean
|
|
|
|
|
asFactoryBean.setDataSource(dataSource());
|
|
|
|
|
return (SessionFactory) asFactoryBean.getObject();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
|
public DataSourcedataSource() {
|
|
|
|
|
return new DriverManagerDataSource(jdbcUrl,
|
|
|
|
|
username, password);
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-04-14 14:59:22 +08:00
|
|
|
</programlisting> To get this to work you need to add the following component
|
|
|
|
|
scanning entry in your minimal application context XML file.
|
|
|
|
|
<programlisting language="java"><context:component-scan
|
|
|
|
|
base-package="com.myco.config"/></programlisting></para>
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
<section>
|
|
|
|
|
<title>Factory Bean definitions using annotations</title>
|
|
|
|
|
|
|
|
|
|
<para>FactoryBeans can be defined within a Spring component definition
|
|
|
|
|
and registered using standard component-scanning techniques. See <link
|
|
|
|
|
linkend="beans-factorybeans-annotations">Factory Bean Definitions
|
|
|
|
|
using annotations</link> for more information</para>
|
|
|
|
|
</section>
|
|
|
|
|
</section>
|
2009-04-08 22:06:01 +08:00
|
|
|
|
2009-04-14 14:59:22 +08:00
|
|
|
<section id="new-feature-rest">
|
|
|
|
|
<title>The Web Tier</title>
|
2009-04-08 22:06:01 +08:00
|
|
|
|
2009-04-14 12:43:15 +08:00
|
|
|
<para>Work in progress ...</para>
|
2009-04-14 14:59:22 +08:00
|
|
|
|
|
|
|
|
<section>
|
|
|
|
|
<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 request
|
|
|
|
|
and replies. </para>
|
|
|
|
|
|
|
|
|
|
<para>The <classname>MarhsallingHttpMessageConverter</classname> uses
|
|
|
|
|
the Object to XML mapping functionality in the
|
|
|
|
|
<literal>org.springframework.oxm</literal> package. This functionality
|
|
|
|
|
had previously been part of Spring Web Services. More information on
|
|
|
|
|
the use of the <literal>org.springframework.oxm</literal> can be found
|
2009-04-14 22:12:28 +08:00
|
|
|
in the <link linkend="oxm">Marshalling XML using O/X Mappers</link> chapter.</para>
|
2009-04-14 14:59:22 +08:00
|
|
|
|
|
|
|
|
<para>Refer to the section on <link linkend="rest">REST support</link>
|
|
|
|
|
for more information.</para>
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
<section>
|
|
|
|
|
<title>@MVC additions</title>
|
|
|
|
|
|
|
|
|
|
<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>
|
|
|
|
|
|
|
|
|
|
<para>Work in progress ...</para>
|
|
|
|
|
</section>
|
2009-04-08 22:06:01 +08:00
|
|
|
</section>
|
|
|
|
|
|
2009-04-14 14:59:22 +08:00
|
|
|
<section id="new-feature-validation">
|
|
|
|
|
<title>Declarative model validation</title>
|
2009-04-03 12:08:08 +08:00
|
|
|
|
2009-04-14 14:59:22 +08:00
|
|
|
<para>Hibernate Validator, JSR 303</para>
|
2009-04-03 12:08:08 +08:00
|
|
|
|
2009-04-14 14:59:22 +08:00
|
|
|
<para>Work in progress...</para>
|
|
|
|
|
</section>
|
2009-04-03 12:08:08 +08:00
|
|
|
|
2009-04-14 14:59:22 +08:00
|
|
|
<section id="new-feature-jee-6">
|
|
|
|
|
<title>Early support for Java EE 6</title>
|
2009-04-03 12:08:08 +08:00
|
|
|
|
2009-04-14 14:59:22 +08:00
|
|
|
<para>JSF 2.0, JPA 2.0, etc</para>
|
2009-04-03 12:08:08 +08:00
|
|
|
|
2009-04-14 14:59:22 +08:00
|
|
|
<para>Work in progress...</para>
|
|
|
|
|
</section>
|
2009-04-14 12:43:15 +08:00
|
|
|
</section>
|
2009-04-01 11:35:39 +08:00
|
|
|
</chapter>
|