Skip to content

Add BeanResolver to the EvaluationContext when creating the Jdbc Query #2018

Closed as not planned
@mipo256

Description

@mipo256

Currently we can use SPEL in queries, like that:

@Query("SELECT * FROM person WHERE id = :#{#person.id}")
Person findWithSpEL(PersonRef person);

When preparing a demo for the audience, I relized, that bean references in SPEL like that:

@Query(value = "SELECT * FROM users WHERE name = :name AND customer = #{@userProperties.customer()}")
Optional<User> findByName(@Param("name") String name);

Does not work and produce an exception:

Caused by: org.springframework.data.repository.query.QueryCreationException: Could not create query for public abstract java.util.Optional my_package.UserRepository.findByName(java.lang.String); Reason: EL1057E: No bean resolver registered in the context to resolve access to bean 'userProperties'

That is likely due to the lack of the BeanResolver in the EvaluationContext, as stated here. It seems to be fairly easy to provide the BeanFactoryResolver in here.

I can take a look at this.

Metadata

Metadata

Assignees

Labels

status: declinedA suggestion or change that we don't feel we should currently apply

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions