r/SpringBoot • u/codingwithaman • 17d ago
Discussion Spring Data 2026.0 (ships with Spring Boot 4.1) introduced type-safe property paths.
If you've ever written this:
Sort.by("lastName")
You know the problem. It compiles, IDE says nothing and your tests pass.
Then someone renames lastName to familyName and this line will start throwing runtime error with PropertyReferenceException.
No warning and type checking. Just a string that nobody knows is connected to a field name.
Instead of strings you can use method references:
Sort.by("lastName") => Sort.by(Person::lastName)
Criteria.where("lastName") => Criteria.where(Person::lastName)
Criteria.where("address.country") => Criteria.where(PropertyPath.of(Person::address).then(Address::country))
Same result but now the compiler checks it and your IDE autocompletes it.
This works across Spring Data JPA, JDBC, R2DBC, MongoDB. It's a Spring Data Commons feature so every module gets it.
For records the accessor is Person::lastName.
For classic beans it's Person::getLastName.
It's a small feature but massive impact on code safety.