Stable Release in branch 4.2
4.2.9
Released 21 Dec 2016
(9 years ago)
SoftwareSpring Framework
Version4.2
Supported
Java versions
Java 6+
Initial release4.2.0
31 Jul 2015
(11 years ago)
Latest release4.2.9
21 Dec 2016
(9 years ago)
End of
OSS support
Unavailable
End of
enterprise support
Unavailable
Source codehttps://github.com/spring-projects/spring-framework/tree/v4.2.9.RELEASE
Documentationhttps://docs.spring.io/spring-framework/docs/4.3.x/spring-framework-reference/html/new-in-4.2.html
Spring Framework 4.2 ReleasesView full list

What Is New in Spring Framework 4.2

Spring Framework 4.2 delivers a range of updates focused on core container refinements, web and messaging enhancements, and improved testing support. This release builds on the foundation of 4.x, adding polish and new capabilities without major breaking changes.

Category Key Updates
Core Container Annotation-driven event listener, @Autowired on constructors changes, Groovy DSL for bean definitions, @AliasFor support in meta-annotations.
Web Improvements @ControllerAdvice with model attributes, @MatrixVariable with @RequestMapping, Jackson @JsonView support, CORS global configuration.
Messaging & WebSocket STOMP client support, SockJS heartbeat, @SendToUser for targeted messaging, binary WebSocket message handling.
Testing JUnit @Rule support, XML context caching, TestContext bootstrapping for JUnit 5 (JUnit Jupiter).
Data Access JPA 2.1 @NamedStoredProcedureQuery support, Hibernate ORM 5.0 compatibility, JCache (JSR-107) annotation support.

How did the core container get smarter in Spring 4.2?

The core container received several quality-of-life improvements that make configuration more expressive. Annotation-based development got a significant boost, which matters because it reduces boilerplate and clarifies intent.

Annotation-Driven Event Listeners

You can now annotate any managed bean method with @EventListener to handle application events. This is cleaner than implementing the ApplicationListener interface. The event type is automatically inferred from the method parameter.

@Service
public class MyService {
    @EventListener
    public void handleContextRefresh(ContextRefreshedEvent event) {
        // React to the event
    }
}

Improved @Autowired and Meta-Annotations

@Autowired became optional on constructors when there's only one. The new @AliasFor annotation allows you to create composed annotations with transparent attribute aliasing, making custom stereotype annotations more powerful.

What web and messaging features were added?

Spring MVC and Spring WebSocket gained practical features for modern web applications. These updates address common developer requests, particularly around REST APIs and real-time communication.

Better MVC Annotations and CORS

@ControllerAdvice can now handle @ModelAttribute methods, centralizing model setup. Global CORS configuration is finally here, letting you define rules in one place instead of per handler. Jackson's @JsonView is integrated for controlling JSON output per request.

STOMP Client and Targeted User Messaging

The framework introduced a STOMP client for use within the application, useful for testing or proxying messages. For WebSocket applications, @SendToUser simplifies sending messages to a single user session without manual destination management.

How does Spring 4.2 improve the testing experience?

Testing support saw incremental but meaningful upgrades, focusing on integration with modern testing frameworks and performance. In practice, these changes make writing integration tests slightly faster and less verbose.

Support for JUnit @Rule objects allows you to integrate custom test rules into the Spring TestContext framework. XML context caching across test suites reduces startup time. Crucially, early support for JUnit 5 (JUnit Jupiter) was added via a new SpringExtension, setting the stage for future migration.

FAQ

Do I need to change my code to upgrade from Spring 4.1 to 4.2?
Mostly no. Spring 4.2 is a backward-compatible release within the 4.x series. You can upgrade and immediately benefit from new features without mandatory changes, barring deprecated API usage.

What's the real-world use for the new @EventListener annotation?
It decouples event handling from the ApplicationListener interface. You can have multiple event handler methods in one bean, each for a different event type, which is cleaner and more maintainable for complex event-driven logic.

How does global CORS configuration work?
You can declare a CorsConfiguration bean and apply it globally via WebMvcConfigurer. This eliminates the need to annotate every @RequestMapping with @CrossOrigin when you have uniform CORS policies.

Is the STOMP client feature for production use?
Yes. The STOMP client (org.springframework.messaging.simp.stomp.StompClient) is designed for use within the Spring application context, such as in a service bean. It's useful for connecting to external message brokers or for integration testing your own WebSocket endpoints.

Does the JUnit 5 support mean I should switch from JUnit 4?
Not immediately. The initial support in 4.2 is foundational and allows you to experiment with JUnit 5's new programming model (JUnit Jupiter) while still running in the JUnit 4 infrastructure. It's a bridge for early adopters; full support came later.

Releases In Branch 4.2

VersionRelease date
4.2.921 Dec 2016
(9 years ago)
4.2.819 Sep 2016
(10 years ago)
4.2.704 Jul 2016
(10 years ago)
4.2.606 May 2016
(10 years ago)
4.2.525 Feb 2016
(10 years ago)
4.2.417 Dec 2015
(10 years ago)
4.2.315 Nov 2015
(10 years ago)
4.2.215 Oct 2015
(11 years ago)
4.2.101 Sep 2015
(11 years ago)
4.2.031 Jul 2015
(11 years ago)
4.2.0.RC315 Jul 2015
(11 years ago)
4.2.0.RC230 Jun 2015
(11 years ago)
4.2.0.RC126 May 2015
(11 years ago)