4.0.9

Latest release in branch 4.0
Released 11 years ago (December 30, 2014)

Software Spring Framework
Branch 4.0
First official release version 4.0.0
First official release date 12 years ago (December 12, 2013)
Supported
Java versions
Java 6+
Source code https://github.com/spring-projects/spring-framework/tree/v4.0.9.RELEASE
Documentation https://docs.spring.io/spring-framework/docs/4.3.x/spring-framework-reference/html/new-in-4.0.html
Spring Framework 4.0 Releases View full list

What Is New in Spring Framework 4.0

Spring Framework 4.0 introduced several major updates focused on modern Java development, improved web capabilities, and enhanced test support. The key changes are summarized in the table below.

Category Key Updates
Java 8 Support Lambda expressions, method references, JSR-310 Date and Time API, and parameter name discovery.
Java EE 7 Support JMS 2.0, JPA 2.1, Bean Validation 1.1, JAX-RS 2.0, and WebSocket API.
Core Container Improvements Generic-qualified dependency injection, @Conditional for bean definitions, and @Description annotation.
Web & WebSocket Enhanced WebSocket support with SockJS fallbacks and STOMP protocol. Spring MVC supports Java 8's java.util.Optional.
Testing First-class support for testing @Configuration classes and bean profiles within the TestContext framework.
Groovy DSL Groovy 2.0+ Bean Definition DSL for external bean configuration.
Deprecations Several deprecated packages and classes (e.g., org.springframework.web.servlet.view.document) were removed.

How did Spring 4.0 improve support for modern Java?

Spring 4.0 fully embraced Java 8 features, making the framework more expressive and type-safe. Lambda expressions and method references can now be used directly within callback scenarios, like in JdbcTemplate or event listeners. This matters because it allows for cleaner, more concise code in your data access and event-handling layers.

The framework also integrates the JSR-310 java.time API. You can use types like LocalDate and Instant directly with Spring's data binding and formatting, eliminating the need for manual conversion from legacy java.util.Date.

Better Dependency Injection with Generics

Generic-qualified autowiring was enhanced. If you have a repository like Repository<Customer>, you can now inject it more precisely into a CustomerService that expects the same generic type. In practice, this reduces ambiguity when you have multiple beans of the same raw type.

What web and messaging features were upgraded?

The web stack received significant updates to align with Java EE 7 standards and modern real-time web requirements. Spring MVC now natively supports Java 8's Optional as a controller method argument or return type, which helps in explicitly communicating optional values.

WebSocket Becomes Production-Ready

WebSocket support, including the SockJS fallback protocol, was stabilized. This allows for bidirectional communication between client and server, essential for features like live chat or notifications. The STOMP sub-protocol support makes it easier to structure messages, similar to how you'd use JMS or AMQP.

Support for JAX-RS 2.0 client API and Bean Validation 1.1 means your RESTful services can leverage the latest standards for building and validating web endpoints.

How was testing simplified in this release?

Testing @Configuration classes became much more straightforward. You can now load these classes directly in your tests without needing component scanning or other workarounds. This is a big win for unit testing your configuration logic in isolation.

The TestContext framework gained the ability to work with bean definition profiles. You can declare an active profile for a specific test class or method, allowing you to test different bean configurations within the same test suite. For example, you can switch between "dev" and "prod" datasources.

@ActiveProfiles("dev")
@ContextConfiguration(classes = TestConfig.class)
public class MyServiceTest {
    // Tests run with the "dev" profile active
}

What was removed or deprecated that I should know about?

Spring 4.0 removed support for several outdated technologies to reduce clutter and maintenance overhead. Key removals include the Portlet MVC framework, which was superseded by modern single-page application approaches and REST APIs.

Packages like org.springframework.web.servlet.view.document (containing outdated PDF/Excel view classes) and org.springframework.jdbc.support.incrementer for certain databases were also removed. If you were using these, you'd need to migrate to more modern libraries like Apache POI directly.

In practice, this cleanup forces an upgrade path but results in a leaner, more focused framework core. Always check the upgrade guide for a full list of deprecated APIs you might still be using.

FAQ

Can I use Spring 4.0 with Java 6 or 7?
Yes, Spring 4.0 maintains compatibility with Java 6 and 7. However, to leverage new features like lambda support and JSR-310, you need to run on Java 8. The core framework still compiles and runs on the older versions.

What is the @Conditional annotation used for?
The @Conditional annotation allows a bean to be registered only if a specific condition is met. It's the foundation for Spring Boot's auto-configuration. You can define your own conditions by implementing the Condition interface.

How do I start using WebSockets in Spring 4.0?
You need to enable WebSocket support with @EnableWebSocket and configure a WebSocketHandler. For a richer messaging model, use STOMP over WebSocket via @EnableWebSocketMessageBroker. Don't forget to configure SockJS fallback options for browsers without WebSocket support.

My project uses removed packages like the JasperReports view classes. What should I do?
You have a couple of options. You can downgrade to Spring 3.x, but that's not recommended. The better path is to directly use the JasperReports API in your controller to generate the report and stream it to the response, or find a third-party library that provides similar Spring integration.

Does Spring 4.0 work with older application servers like WebLogic 10.3?
It can, but you might face challenges. Since Spring 4.0 supports Java EE 7, which is newer than the Java EE 5 or 6 standards in older servers, you may need to exclude certain modules (like the WebSocket implementation) or ensure you deploy with the correct library versions to avoid classloading conflicts.

Releases In Branch 4.0

Version Release date
4.0.9 11 years ago
(December 30, 2014)
4.0.8 11 years ago
(November 11, 2014)
4.0.7 11 years ago
(September 04, 2014)
4.0.6 11 years ago
(July 08, 2014)
4.0.5 11 years ago
(May 20, 2014)
4.0.4 11 years ago
(April 30, 2014)
4.0.3 12 years ago
(March 27, 2014)
4.0.2 12 years ago
(February 19, 2014)
4.0.1 12 years ago
(January 28, 2014)
4.0.0 12 years ago
(December 12, 2013)