Iii. new features and enhancements to Spring Framework 4.0

Source: Internet
Author: User
Tags deprecated stomp java se

The Spring Framework was first released in 2004, and significant changes have occurred since Spring 2.0 provides XML namespaces and ASPECTJ support; Spring 2.5 incorporates a note-driven configuration, and Spring 3.0 introduces a powerful Java 5+ Foundation in the framework code base and features such as Java-based @configuration models. version 4.0 is the latest major version of the spring framework and the first version that fully supports Java 8 features, and you can still use the old version of Java, but now you have raised the minimum requirement to Java SE 6, we also took advantage of a major version of the opportunity to delete many deprecated classes and methods. The Migration Guide for upgrading to Spring 4.0 is available on the Spring framework's GitHub wiki. 3.1 Improved the introductory experiencethe new Spring. The IO site provides a series of "Getting Started" guides to help you learn Spring. you can read more about the guide in the first chapter and start using the Spring section in this document. This new site also provides a comprehensive overview of many of the projects published under the spring architecture. If you are a MAVEN user, you may also be interested in the Pom file for each spring framework release that is now released. 3.2 Removing deprecated packages and methodsall deprecated packages, as well as many deprecated classes and methods, were removed in version 4.0. If you are upgrading from a previous spring version, you should make sure that you have fixed an unsupported call to outdated APIs. for all changes, please review the API diff report. Note that optional third-party dependencies have been raised to a minimum of 2011/2011 years (that is, Spring 4 usually only supports versions released at the end of 2010 or later); it's worth noting that Hibernate 3.6+, EhCache 2.1+, Quartz 1.8+, Groovy 1.8+ and Joda-time 2.0+. Spring 4 requires the latest Hibernate Validator 4.3+, and the support for Jackson has been focused on 2.0+ (support for jackson1.8/1.9, which was owned by Spring 3.2, has now been deprecated). 3.3 Java 8 (and 6 and 7)Spring Framework 4.0 provides support for several Java 8 features. You can use the spring callback interface to work with lambda expressions and method references. with the best support for Java.time (JSR-310), Some existing annotations have been transformed into @Repeatable. You can also use Java 8 's parameter name Discovery (based on the -parameters compiler Flag) as an alternative to enabling debugging information. Spring is still compatible with older versions of Java and JDK: Specifically, Java SE 6 (specifically, the lowest JDK 6 update to 18 released in January 2010) is still fully supported, but for projects based on Spring 4, we recommend using Java Version 7 or 8. 3.4 Java EE 6 and 7Java EE version 6 or later is now considered the most basic standard for using Spring Framework 4, and the JPA 2.0 and Servlet 3.0 specifications have special dependencies. To stay compatible with Google App Engine and legacy application servers, you can deploy a spring 4 application to a servlet 2.5 environment. However, it is highly recommended to use servlet 3.0+, and in spring testing, this is a primary condition for test settings in the development environment. If you are a WebSphere 7 user, be sure to install the JPA 2.0 Feature Pack. In WebLogic 10.3.4 or later, install the JPA 2.0 patch with it. This allows both servers to be converted to a spring 4-compliant deployment environment. in the long run, the Spring Framework 4.0 supports Java EE 7-level specifications: In particular, JMS 2.0, JTA 1.2, JPA 2.1, Bean Validation 1.1, and jsr-236 concurrency utility. As always, this support focuses on the individual use of these specifications, such as in Tomcat or stand-alone environments. However, when you deploy a spring application to a Java EE 7 server, it works just as well. Note that Hibernate 4.3 is the provider of JPA 2.1, so it only supports the Spring Framework 4.0. the same is true for Hibernate Validator 5.0 as the provider of Bean Validation 1.1 . None of these two versions is officially supported by Spring Framework 3.2. 3.5 Groovy Bean definition DSLstarting with the Spring Framework 4.0, you can use the groovy DSL to define an external bean configuration. Thinking is similar to the XML bean definition But allows for a more concise syntax. Using Groovy allows you to embed bean definitions directly in the bootstrap code, for example:
def reader = new Groovybeandefinitionreader (myapplicationcontext)
Reader.beans {
DataSource (basicdatasource) {
driverclassname = "Org.hsqldb.jdbcDriver"
url = "Jdbc:hsqldb:mem:grailsDB"
username = "sa"
password = ""
settings = [mynew: "Setting"]
    }
sessionfactory (sessionfactory) {
DataSource = DataSource
    }
MyService (myservice) {
Nestedbean = {Anotherbean Bean
DataSource = DataSource
        }
    }
}
to learn more, please see groovybeandefinitionreader javadocs. 3.6 Improvement of the core containerThe core container has several overall improvements:1. Spring now takes the generic type as the qualifier when injecting the bean. For example, if you are using Spring Data Repository, you can now easily inject a specific implementation:@Autowired repository<customer> Customerrepository. 2 . If you use spring's meta-annotations, you can now develop a custom comment that exposes a specific property from the source comment. 3. When these beans are automatically assembled into lists and arrays, they can be sorted. @Order Annotations and Ordered interfaces are supported . 4. @Lazy Annotations can now be used on the injection point or in the @bean definition. 5. For developers who use Java-based configuration, @description comments are already described. 6. The common model of conditional filter Bean is added by @Conditional annotation. This is similar to @Profile support but allows users to customize the way they are programmed. 7. The cglib-based proxy class no longer requires a default constructor. Support is provided through the objenesis Library, which is repackaged and distributed as part of the spring framework. With this policy, no more constructors are used to invoke the proxy instance. 8. There are now managed time zone support throughout the framework, such as in Localecontext 3.7 General web improvementsdeploying to a servlet 2.5 server is still an option, but Spring Framework 4.0 is now focused on the servlet 3.0+ environment. If you are using the Spring MVC Test Framework, you will need to make sure that the Servlet 3.0 compatible jar is in your test classpath. In addition to the WebSocket support mentioned later, the following comprehensive improvements have been made to the Spring Web module:1. You can use the new @restcontroller annotations to work with the spring MVC application, eliminating the need to add @responsebody to each @requestmapping method. 2. Added the Asyncresttemplate class to allow non-blocking asynchronous support while developing the rest client. 3. Spring now provides full time zone support when developing a spring MVC application. 3.8 websocket,sockjs and Stomp Messaginga new Spring WebSocket module provides comprehensive support for Web-based bidirectional communication between clients and servers in a Web application. It is compatible with the Jsr-356,java WebSocket API and provides a sockjs-based fallback option (that is, WebSocket emulation) for use in browsers that do not support the WebSocket protocol, such as Internet Explorer less than 10 version). a new Spring-messaging The module adds support for stomp, which is the WebSocket sub-protocol used in the application, and an annotated programming model for Routing and processing stomp messages from WebSocket clients. Therefore, @controller can now contain @RequestMapping @MessageMapping spring-messaging module also contains the previous from spring Key abstractions extracted in the integration project, such as  message, messagechannel, messagehandlerFor more details, including a more comprehensive introduction, see Chapter 25th, "WebSocket support" section. 3.9 Test ImprovementsIn addition to collating obsolete code in the Spring-test module, Spring Framework 4.0 introduces some new features for unit and integration testing. 1. Almost all annotations can be used in the spring-test module (e.g.:@ContextConfiguration, @WebAppConfiguration, @ Contexthierarchy, @ActiveProfiles and so on. ), you can now create custom, custom composite annotations as meta annotations and reduce duplicate configurations in your tests. 2. Now, by implementing a custom Activepro file parser and registering it with the parser property of @activeprofiles, you can programmatically resolve the active bean definition profile. 3. A new Socketutils class is introduced in the Spring core module , which allows you to scan the free TCP and UDP server ports on the local host. This feature is not test-specific, but it can prove useful when writing integration tests that require sockets, such as starting tests for in-memory SMTP servers, FTP servers, servlet containers, and so on. 4. In spring 4.0, theOrg.springframework.mock.web package is now based on the Servlet 3.0 API. In addition, there are several servlet API simulations (for example:mockhttpservletrequest, mockservletcontextT, etc.) that update some minor improvements and improvements to the configuration.  

Iii. new features and enhancements to Spring Framework 4.0

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.