Description
I'm having a problem using a bean in a SPEL @Value
expression by combining Projections and Specifications.
Example project : spring-jpa-projections-specs.zip
In the attached project, a projection returned by a @Query
works correctly, while a projection returned by JpaSpecificationExecutor.findBy(Specification spec) returns an error during http serialization.
CityProjection :
@Value("#{@projectionHelper.fullName(target.name, target.country)}") String getFullName();
In CityServiceImpl line 79 :
CityProjection = this.cityRepository.findByNameAndCountry(name, country);
=> works well
CityProjection = this.cityRepository.findBy(new Specification<City>() { @Override public Predicate toPredicate(Root<City> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) { return null; } }, q -> q.as(CityProjection.class).firstValue());
=> fails with message :
Resolved [org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: EL1057E: No bean resolver registered in the context to resolve access to bean 'projectionHelper']
How can I solve this ?