What Is New in Spring Framework 4.3
Spring Framework 4.3 is a refinement release packed with enhancements that streamline development and reduce boilerplate code. It focuses on convention-over-configuration, especially for web and data access layers, and introduces better support for the latest Java and web standards. This version makes your daily coding tasks more efficient.
| Category | Key Updates |
|---|---|
| Core Container | Implicit constructor injection for single-constructor classes, @Autowired optional on such constructors, improved @EventListener detection. |
| Web MVC & WebFlux | Composed annotation support for @RequestMapping, new @GetMapping, @PostMapping etc. annotations, built-in support for HTTP PATCH method, improved @ResponseStatus on exceptions. |
| Testing | New TestContext feature for executing SQL scripts, JUnit 5 support (preliminary), new @Commit annotation, relaxed rules for @Transactional test methods. |
| Data Access | Spring Data query-by-example support, JpaRepository retrieval methods can return Java 8 Optional, @Transactional support for proxy modes and propagation types. |
| Miscellaneous | Support for Java 8's java.time and java.util.Optional across the framework, improved log4j 2 support, Apache POI 3.17+ support. |
How does Spring 4.3 reduce boilerplate in my controllers?
It introduces a set of composed @RequestMapping shortcut annotations. You no longer need to write @RequestMapping(method = RequestMethod.GET). Instead, you can use @GetMapping, @PostMapping, @PutMapping, @DeleteMapping, and @PatchMapping directly on handler methods.
This makes controller code more readable and concise. In practice, it's a small change that significantly cleans up your web layer definitions.
// Old way
@RequestMapping(value = "/users/{id}", method = RequestMethod.GET)
public User getUser(@PathVariable Long id) { ... }
// New in 4.3
@GetMapping("/users/{id}")
public User getUser(@PathVariable Long id) { ... }
What are the improvements for dependency injection?
Spring 4.3 can perform implicit constructor injection for classes with a single constructor. If you have one constructor, the @Autowired annotation becomes optional. The framework will automatically wire dependencies through that constructor.
This matters because it promotes a cleaner, constructor-injection style without annotation noise. It encourages immutable components and simplifies configuration for typical service and repository beans.
// Before: @Autowired was required
@Service
public class MyService {
private final MyRepository repo;
@Autowired
public MyService(MyRepository repo) {
this.repo = repo;
}
}
// With 4.3: @Autowired is optional
@Service
public class MyService {
private final MyRepository repo;
public MyService(MyRepository repo) { // Implicitly autowired
this.repo = repo;
}
}
What new testing features were added?
The TestContext framework now supports executing SQL scripts during the test lifecycle using the new @Sql annotation. You can also use @SqlConfig to define script execution behavior. A new @Commit annotation indicates that a transactional test method should commit the transaction instead of the default rollback.
These features give you finer control over test database state. The @Sql support is particularly useful for setting up complex data scenarios without embedding SQL in Java code or using external fixtures.
@RunWith(SpringRunner.class)
@ContextConfiguration
@Sql("/test-data.sql") // Script runs before test method
@Sql(scripts = "/cleanup.sql", executionPhase = AFTER_TEST_METHOD)
public class MyRepositoryTest {
@Test
@Commit // Transaction is committed
public void testWithCommittedData() { ... }
}
How does Spring 4.3 handle modern Java types?
Framework support for Java 8's java.time (JSR-310) and java.util.Optional is now integrated across core Spring abstractions. For example, Spring Data repository methods can return Optional<T> instead of a nullable result. Controllers can also accept or return java.time types for seamless JSON/XML serialization.
This allows you to write more modern, null-safe code when interacting with Spring's data layer. It aligns the framework with idiomatic Java 8 patterns developers are already using.
// Spring Data JpaRepository
public interface UserRepository extends JpaRepository<User, Long> {
Optional<User> findByEmailAddress(String email);
}
// In a controller
@GetMapping("/events/{date}")
public List<Event> getEventsOnDate(@PathVariable @DateTimeFormat(iso = ISO.DATE) LocalDate date) {
return service.findByDate(date);
}
FAQ
Do I need to use Java 8 for Spring Framework 4.3?
No, Java 6, 7, and 8 are all supported. However, to use the new java.time and Optional support, you must be on Java 8. The framework itself is compiled with Java 8 but maintains runtime compatibility with earlier versions.
Are the new @GetMapping annotations just syntactic sugar?
Yes, but they are more than that. They are meta-annotated with @RequestMapping and the specific HTTP method. This makes them composable and usable in your own custom annotations, promoting a declarative style.
Is constructor injection without @Autowired safe with multiple constructors?
No. The implicit injection only works when there is exactly one constructor. If you have multiple constructors, you must still annotate the one you want Spring to use with @Autowired.
Can I use JUnit 5 with Spring 4.3?
Spring Framework 4.3 offers preliminary, basic support for JUnit 5 (via the junit-platform). However, full integration with the Spring TestContext Framework is a goal for a future release. For production tests, JUnit 4 is still the primary supported version.
What happened to the @Configuration bean definition "lite" mode?
It's still there and enhanced. In 4.3, @Bean methods on plain @Component classes (so-called "lite" mode) better support inter-bean references and even some dependency injection features, blurring the line between full @Configuration and component classes.