Skip to content

Problem with Spring Data JPA with projections, specifications and SPEL #3410

Closed
@z8manu8z

Description

@z8manu8z

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 ?

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions