`

New Features and Enhancements in Spring 3.0

阅读更多

http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/overview.html

 

2. New Features and Enhancements in Spring 3.0

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.

2.1 Java 5

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.

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).

2.2 Improved documentation

The Spring reference documentation has also substantially been 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 during lunch, please do bring the error to the attention of the Spring team by raising an issue .

2.3 New getting started tutorial

There is now a new getting started tutorial for developing a basic Spring 3.0 MVC web application. This tutorial is a separate document that can be found at the Spring Documentation page.

2.4 New module organization and build system

The framework modules have been revised and are now managed separately with one source-tree per module jar:

  • org.springframework.aop

  • org.springframework.beans

  • org.springframework.context

  • org.springframework.context.support

  • org.springframework.expression

  • org.springframework.instrument

  • org.springframework.jdbc

  • org.springframework.jms

  • org.springframework.orm

  • org.springframework.oxm

  • org.springframework.test

  • org.springframework.transaction

  • org.springframework.web

  • org.springframework.web.portlet

  • org.springframework.web.servlet

  • org.springframework.web.struts

We are now using a new Spring build system as known from Spring Web Flow 2.0. This gives us:

  • Ivy-based "Spring Build" system

  • consistent deployment procedure

  • consistent dependency management

  • consistent generation of OSGi manifests

2.5 Overview of new features

This is a list of new features for Spring 3.0. We will cover these features in more detail later in this section.

  • Spring Expression Language

  • IoC enhancements/Java based bean metadata

  • General-purpose type conversion system and field formatting system

  • Object to XML mapping functionality (OXM) moved from Spring Web Services project

  • Comprehensive REST support

  • @MVC additions

  • Declarative model validation

  • Early support for Java EE 6

  • Embedded database support

2.5.1 Core APIs updated for Java 5

BeanFactory interface returns typed bean instances as far as possible:

  • T getBean(Class<T> requiredType)

  • T getBean(String name, Class<T> requiredType)

  • Map<String, T> getBeansOfType(Class<T> type)

Spring's TaskExecutor interface now extends java.util.concurrent.Executor :

  • extended AsyncTaskExecutor supports standard Callables with Futures

New Java 5 based converter API and SPI:

  • stateless ConversionService and Converters

  • superseding standard JDK PropertyEditors

Typed ApplicationListener<E>

2.5.2 Spring Expression Language

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 Spring Expression Language (SpEL).

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 SpringSource Tool Suite .

The following is an example of how the Expression Language can be used to configure some properties of a database setup

<bean
 class
="mycompany.RewardsTestDatabase"
>
    <property
 name
="databaseName"

        value
="#{systemProperties.databaseName}"
/>
    <property
 name
="keyGenerator"

        value
="#{strategyBean.databaseKeyGenerator}"
/>
</bean
>

This functionality is also available if you prefer to configure your components using annotations:

@Repository 
public
 class
 RewardsTestDatabase {

    @Value("#{systemProperties.databaseName}"
)
    public
 void
 setDatabaseName(String dbName) { … }

    @Value("#{strategyBean.databaseKeyGenerator}"
)
    public
 void
 setKeyGenerator(KeyGenerator kg) { … }
}

2.5.3 The Inversion of Control (IoC) container

2.5.3.1 Java based bean metadata

Some core features from the JavaConfig project have been added to the Spring Framework now. This means that the following annotations are now directly supported:

  • @Configuration

  • @Bean

  • @DependsOn

  • @Primary

  • @Lazy

  • @Import

  • @ImportResource

  • @Value

Here is an example of a Java class providing basic configuration using the new JavaConfig features:

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);
    }
}

To get this to work you need to add the following component scanning entry in your minimal application context XML file.

<context:component-scan
 base-package
="org.example.config"
/>
<util:properties
 id
="jdbcProperties"
 location
="classpath:org/example/config/jdbc.properties"
/>
        

Or you can bootstrap a @Configuration class directly using AnnotationConfigApplicationContext :

public
 static
 void
 main(String[] args) {
    ApplicationContext ctx = new
 AnnotationConfigApplicationContext(AppConfig.class
);
    FooService fooService = ctx.getBean(FooService.class
);
    fooService.doStuff();
}

See Section 3.11.2, “Instantiating the Spring container using AnnotationConfigApplicationContext” for full information on AnnotationConfigApplicationContext .

2.5.3.2 Defining bean metadata within components

@Bean annotated methods are also supported inside Spring components. They contribute a factory bean definition to the container. See Defining bean metadata within components for more information

2.5.4 General purpose type conversion system and field formatting system

A general purpose type conversion system 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.

In addition, a formatter 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.

2.5.5 The Data Tier

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 org.springframework.oxm package. More information on the use of the OXM module can be found in the Marshalling XML using O/X Mappers chapter.

2.5.6 The Web Tier

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.

2.5.6.1 Comprehensive REST support

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 RestTemplate class in the spirit of other template classes such as JdbcTemplate and JmsTemplate . Both server and client side REST functionality make use of HttpConverter s to facilitate the conversion between objects and their representation in HTTP requests and responses.

The MarshallingHttpMessageConverter uses the Object to XML mapping functionality mentioned earlier.

Refer to the sections on MVC and the RestTemplate for more information.

2.5.6.2 @MVC additions

A mvc namespace has been introduced that greatly simplifies Spring MVC configuration.

Additional annotations such as @CookieValue and @RequestHeaders have been added. See Mapping cookie values with the @CookieValue annotation and Mapping request header attributes with the @RequestHeader annotation for more information.

2.5.7 Declarative model validation

Several validation enhancements , including JSR 303 support that uses Hibernate Validator as the default provider.

2.5.8 Early support for Java EE 6

We provide support for asynchronous method invocations through the use of the new @Async annotation (or EJB 3.1's @Asynchronous annotation).

JSR 303, JSF 2.0, JPA 2.0, etc

2.5.9 Support for embedded databases

Convenient support for embedded Java database engines , including HSQL, H2, and Derby, is now provided.

<!-- Begin LoopFuse code-->

<script src="http://loopfuse.net/webrecorder/js/listen.js" type="text/javascript"></script><script src="http://lfov.net/webrecorder/g/chimera.js?vid=4f485958-2107-42da-84c1-9bf1180e5f45" type="text/javascript"></script><script type="text/javascript"> _lf_cid = &quot;LF_48be82fa&quot;; _lf_remora(); </script>

<!-- End LoopFuse code-->

<script type="text/javascript"> var gaJsHost = ((&quot;https:&quot; == document.location.protocol) ? &quot;https://ssl.&quot; : &quot;http://www.&quot;); document.write(unescape(&quot;%3Cscript src='&quot; + gaJsHost + &quot;google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E&quot;)); </script><script src="http://www.google-analytics.com/ga.js" type="text/javascript"></script>

<!-- Begin 2nd Google code - a mod -->

<script type="text/javascript"> var gaJsHost = ((&quot;https:&quot; == document.location.protocol) ? &quot;https://ssl.&quot; : &quot;http://www.&quot;);document.write(unescape(&quot;%3Cscript src='&quot; + gaJsHost + &quot;google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E&quot;));</script><script src="http://www.google-analytics.com/ga.js" type="text/javascript"></script><script type="text/javascript">var pageTracker = _gat._getTracker(&quot;UA-2728886-3&quot;); pageTracker._setDomainName(&quot;none&quot;);pageTracker._setAllowLinker(true); pageTracker._trackPageview();var OrgTracker = _gat._getTracker(&quot;UA-2728886-2&quot;); OrgTracker._trackPageview();</script>

<!-- End 2nd Google code -->
分享到:
评论

相关推荐

    Web Services Enhancements 3.0 Hands On Lab - Security

    6. **Trust and Federation**: WSE3.0支持WS-Trust和WS-Federation,这两个标准允许不同安全域之间的信任和身份验证。这在多组织协作和云服务中特别有用,因为它简化了跨组织的身份验证流程。 7. **Hands-on Lab ...

    IBM Redbook: WebSphere MQ V7.0 Features and Enhancements

    ### IBM Redbook: WebSphere MQ V7.0 特性和增强功能 #### 一、概述与背景 IBM WebSphere MQ(消息队列)是业界领先的消息中间件解决方案,旨在为分布式应用程序提供可靠、高效的数据传输服务。...

    Web Services Enhancements 3.0

    ### Web Services Enhancements 3.0 (WSE 3.0):构建安全的企业级Web服务 #### 一、概述 Web Services Enhancements (WSE) 是由Microsoft开发的一个工具包,它为.NET Framework下的Web服务提供了额外的功能,特别是...

    Spring 5 Design Patterns-Packt Publishing(2017).pdf

    Spring 5 introduces many new features and enhancements from its previous version. We will discuss all this in the book. Spring 5 Design Patterns will give you in-depth insight about the Spring ...

    WebSphere MQ V7.0 Features and Enhancements

    ### WebSphere MQ V7.0 特性和增强 #### 执行摘要 IBM 的 WebSphere MQ V7.0 是一个企业级消息传递系统,为应用程序之间的可靠数据交换提供了一个强大而灵活的基础。本版本包含了多项重要的特性和增强功能,旨在...

    The Java Tutorials (Include Java SE 7 Features and Enhancements)

    The Java Tutorials are practical guides for programmers who want to ... They include hundreds of complete, working examples, and dozens of lessons. Groups of related lessons are organized into "trails".

    5G NR and Enhancements From R15 to R16.pdf

    5G R15到R16演进及R17展望

    Video Rental System

    New features and enhancements as in (4/7/2005): - 1. Start-up Splash screen that dynamically changes whenever you logoff/logon. 2. Application screens titles that allow you to specify your Business ...

    Addison.Wesley.Microsoft.SQL Server 2000-A Guide to Enhancements and New Features

    一本书 Addison.Wesley.Microsoft.SQL Server 2000-A Guide to Enhancements and New Features

    Introducing Gradle(Apress,2015)

    It includes the new features and enhancements found in the latest version of Gradle, an open source enhanced Java build and release tool for Java that is especially popular among Spring application ...

    Apache Spark 2.4 and beyond

    Xiao Li and Wenchen Fan offer an overview of the major features and enhancements in Apache Spark 2.4. Along the way, you’ll learn about the design and implementation of V2 of theData Source API and ...

    Swift 3 Object Oriented Programming, 2nd Edition [PDF]

    This book is developed with XCode 8.x and covers all the enhancements included in Swift 3.0. In addition, we teach you to run most of the examples with the Swift REPL available on macOS and Linux, ...

    C#3.0 Language Enhancements

    ### C#3.0语言增强特性详解 #### 引言 C#3.0作为C#语言的一个重要版本,引入了一系列新的语言特性,这些新特性不仅增强了开发者的生产力,还提高了代码的可读性和可维护性。本篇将详细介绍C#3.0中的主要新特性及其...

    Swift 3 Object-Oriented Programming

    This book is developed with XCode 8.x and covers all the enhancements included in Swift 3.0. In addition, we teach you to run most of the examples with the Swift REPL available on macOS and Linux, ...

    Swift.3.Object.Oriented.Programming.2nd.epub

    This book is developed with XCode 8.x and covers all the enhancements included in Swift 3.0. In addition, we teach you to run most of the examples with the Swift REPL available on macOS and Linux, ...

    Introducing Maven(Apress,2014)

    This fully packed mini-book includes the new features and enhancements found in the latest version of Maven. In this short 100-page book, you'll learn all about Maven and how to set it up to use. ...

    Enterprise Library 3.0

    This release of the Enterprise Library includes two new application blocks, a software factory for creating application blocks and providers, and other new features and enhancements.

    Advances in OpenGL ES 3.0

    See how the innovations in OpenGL ES 3.0 deliver incredible graphics in games and other mobile 3D apps. Learn about advanced effects enabled by the latest API enhancements, and get specific tips and ...

    英文原版-Windows 7 The Definitive Guide 1st Edition

    You’ll learn all of the features and enhancements in complete detail, along with specifics for configuring the operating system to put you in full control. Bestselling author and Windows expert ...

    Apress.Introducing.Java.EE.7.Jul.2013.epub 完整版本

    Introducing Java EE 7: A Look at What’s New guides you through the new features and enhancements in each of the technologies comprising the Java EE platform. 格式:epub,完整版本

Global site tag (gtag.js) - Google Analytics