Spring Description Document Translation 2--second part Spring3.0 new features

Source: Internet
Author: User
Tags aop http request svn java se

Part II Spring3.0 new features
New features and enhancements in 2.spring3.0


If you have been using spring, you will know that spring has gone through two important editions: the Spring2.0 of October 2006 and the Spring2.5 of November 2007. Now, Spring3.0 is the third most important version.

(Java SE and Java EE support: The spring framework now fully supports Java 5 and Java 6.) In addition, spring is compatible with EE 1.4 and Java EE 6, with some simple support for the Java EE6.

2.1 Java 5
The whole framework is modified for the features of Java 5 such as generics, variable length parameters and so on. We do our best to keep the code forward compatible. On the interface of Spring AOP, solutions that are compatible with existing generic collections, maps, Factorybeans, and Bridge methods. A generic application listens for automatic authentication of events of a specified type. Now, all of the callback interfaces, such as Transactioncallback and hibernatecallback, define a common result. In summary, the spring code base has made the latest improvements and optimizations for Java 5.

Spring's taskexecutor is updated with the Java.util.concurrent integration of Java 5. Now these support are provided in a class-by-level manner like Executorservice adapters and threadfactory. Make it possible to follow the JSR-236 standard. In addition we added a new tag @async for asynchronous method calls.

2.2 Document Improvements
The spring documentation also updates these new features and improvements in Spring3.0. We do our best to ensure that there are no errors in the document, but errors are unavoidable. If you find any problems or errors, please send the error description to the spring team.

2.3 New Documents and tutorials
We have a lot of very good documentation and tutorials to teach you how to use the various features of SPRING3. They are all in the Spring document page.

The example modifies the update for the new feature of Spring3. In addition, the example is removed from the original code to a dedicated SVN directory:
https://anonsvn.springframework.org/svn/spring-samples/

Similarly, the example is no longer packaged with Spring3 and needs to be downloaded separately. However, this document will continue to refer to some examples (especially like petclinic) to illustrate functionality.

Note that subversion or SVN has more information, see Project Home http://subversion.apache.org/


2.4 New modular organization and system construction
The modules in the framework are modified and each module source number is managed independently
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

Like you know. Starting with the spring Web Flow2.0, we use the new spring build system, which involves:

ivy-based "Spring Build" system

Consistent deployment procedure

Consistent dependency Management

Consistent generation of OSGi manifests

2.5 new features preview

Here's a list of new features for Spring3.0, and more about features, which will appear in later chapters.

。 Spring Expression Language
。 IOC enhanced/Java-based bean meta data
。 Multi-purpose type conversion systems and member formatting systems.
。 Objects from the Spring Web Services project to the XML mapping feature (OXM).
。 Extensive rest support
。 @MVC tag
。 Declaring model validation
。 Early support for Java EE 6
。 Support for embedded databases

2.5.1 Core API updates for Java 5

The Beanfactory interface return type may be:
。 T Getbean (class<t> requiredtype)
。 T Getbean (String name, class<t> requiredtype)
。 Map<string, t> getbeansoftype (class<t> type)

The Spring Taskexecutor interface now extends Java.util.concurrent.Executor:
。 Sub-interface Asynctaskexecutor support Standard call interface

New Java 5-based conversion from API to SPI
。 Stateless conversion services and converters
。 Replace the standard JDK property editor

Typed applicationlistener<e>

2.5.2 Spring Description Language
Spring provides an expression language similar to Unified El, which has a much more language feature than unified El. Expression statements can be used when defining XML and annotation-based bean definitions, and he serves the entire spring functionality, including code-completion requirements based on the Eclipse Spring source Tool suite.

The following is the use of the expression language to complete database property settings.

<bean class= "MyCompany. Rewardstestdatabase ">
<property name= "DatabaseName"
Value= "#{systemproperties.databasename}"/>
<property name= "Keygenerator"
Value= "#{strategybean.databasekeygenerator}"/>
</bean>


If you prefer to use the annotation configuration in your program, it is OK, as follows:
@Repository
public class Rewardstestdatabase {

@Value ("#{systemproperties.databasename}")
public void Setdatabasename (String dbname) {...}

@Value ("#{strategybean.databasekeygenerator}")
public void Setkeygenerator (keygenerator kg) {...}
}

2.5.3 Reverse Control (IoC) container

2.5.3.1 metadata for Java-based beans

Some of the features of the Javaconfig project are now added to the spring framework. This means that the following comments are directly supported:

@Configuration

@Bean

@DependsOn

@Primary

@Lazy

@Import

@ImportResource

@Value

Here's an example of using the new feature to provide a basic configuration for Java classes:
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 them working, you need to add the following components to scan your application for XML files

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

Alternatively, you can use the @configuration tag directly on the Annotationconfigapplicationcontext class, as follows:
public static void Main (string[] args) {
ApplicationContext CTX = new Annotationconfigapplicationcontext (appconfig.class);
Fooservice Fooservice = Ctx.getbean (Fooservice.class);
Fooservice.dostuff ();
}

Chapter 3.11.2 "Using Annotationconfigapplicationcontext to install the Spring container" is a more comprehensive description of Annotationconfigapplicationcontext.

2.5.3.2 defines bean metadata within a component

The Spring component support method uses @bean annotations. They are defined through a factory bean to a container. See the section "Defining bean Metadata within a component" to see more information.

2.5.4 Common type conversion system and field format system

The universal type conversion system is introduced into the Spring3.0. The system is spel for type conversion, or it can be used at the time of the spring container and DataBinder bean property bindings.

In addition, formatting the field values with the formatted SPI is introduced into the Spring3.0. The SPI provides a robust alternative to the client environment (such as: SPRINGMVC) than the JavaBean property editor.

2.5.5 Data Layer

The object to XML mapping feature (OXM) is moved from the Spring Web Services project to the spring core framework. The function is in the ORG.SPRINGFRAMEWORK.OXM package. More information is described in more detail in the OXM Module section of the section "Editing XML using the o/x mapper."

2.5.6 Web Layer

Supporting the building of RESTful Web service and Web applications is a very exciting feature. Some new annotations are also available for use in Web applications.

2.5.6.1 Full Rest support

Server-side support for building restful applications is supported as an extension of an existing annotation-driven MVC web framework. Client support is supported by resttemplate like other templates (such as JdbcTemplate, Jmstemplate). The rest functionality of both the client and the server uses Httpconverter to convert between the object and the HTTP request and corresponding.

The ability to use Marshallinghttpmessageconverter for object to XML mapping in the early days.

See MVC and Resttemplate chapters.

2.5.6.2 @MVC Markup Extension

The MVC namespace introduces a very simple spring MVC configuration

Additional markup @CookieValue and @RequestHeaders are added. See "Using @CookieValue Mapping cookie Values" and "using @RequestHeaders Mapping Request Header Properties" section for more information.

2.5.7 Definition Model Validation

There are some enhancements to validation, including JSR303 support using hibernate validation as the default validation.

2.5.8 early Java EE 6 support

Supports declaring asynchronous methods through a new @Async tag (or EJB3.1 @Asynchronous tag).

Jsr303,jsf2.0,jpa2.0 and so on.

2.5.9 supports embedded databases

Easy support for the embedded Java database engine, including HSQL,H2 and Derby.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.