This project stopped working after upgrade from Spring Boot 3.2.0 to 3.2.1.
The error message is quite long and nested and points to a problem with GenericRepository#findProjectedById method (At least 2 parameter(s) provided but only 1 parameter(s) present in query):
2024-01-09T21:02:14.081+02:00 WARN 25839 --- [ restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'webSecurityConfig' defined in file [/home/martin/Dev/Marketplace/target/classes/bg/softuni/marketplace/config/WebSecurityConfig.class]: Unsatisfied dependency expressed through constructor parameter 0: Error creating bean with name 'userService' defined in file [/home/martin/Dev/Marketplace/target/classes/bg/softuni/marketplace/service/UserServiceImpl.class]: Unsatisfied dependency expressed through constructor parameter 0: Error creating bean with name 'userRepository' defined in bg.softuni.marketplace.repository.UserRepository defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: Could not create query for public abstract java.util.Optional bg.softuni.marketplace.repository.GenericRepository.findProjectedById(java.lang.Object,java.lang.Class); Reason: Failed to create query for method public abstract java.util.Optional bg.softuni.marketplace.repository.GenericRepository.findProjectedById(java.lang.Object,java.lang.Class); At least 2 parameter(s) provided but only 1 parameter(s) present in query
The findProjectedById method uses a dynamic projection and is defined in the GenericRepository interface as follows:
@Validated
@NoRepositoryBean
public interface GenericRepository<E, I> extends JpaRepository<E, I> {
<T extends Viewable<E>> Optional<T> findProjectedById(@NotNull I id, @NotNull Class<T> projection);
//...
}
GenericRepository interface in turn is used by the UserRepository:
@Validated
@Repository
public interface UserRepository extends GenericRepository<User, UUID> {
//...
}
The method is used only once in the code in UserServiceImpl:
@Override
public Optional<String> getUsernameById(@NotNull UUID id) {
return userRepository
.findProjectedById(id, UserUsernameProjection.class)
.map(UserUsernameProjection::getUsername);
}
And here is the UserUsernameProjection interface:
public interface UserUsernameProjection extends Viewable<User> {
String getUsername();
}
Release Notes of Spring Boot 3.2.1 or Spring Framework 6.1.2 miss information of a breaking change like that and I wasn't able to find other mentions of such problem here, so any hints in the right direction will be highly appreciated.
Thank you!