Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
mipo256 opened this issue Mar 16, 2025 · 3 comments
Closed
Assignees
Labels
status: declined A suggestion or change that we don't feel we should currently apply

Comments

@mipo256
Copy link
Contributor

mipo256 commented Mar 16, 2025

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.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 16, 2025
@mp911de mp911de self-assigned this Mar 17, 2025
@mp911de
Copy link
Member

mp911de commented Mar 17, 2025

Our SpEL expressions deliberately do not wire the bean resolver as we provide a SPI to extend SpEL functionality. You need to register a EvaluationContextExtension that exposes contextual functionality for SpEL.

@mp911de mp911de added status: declined A suggestion or change that we don't feel we should currently apply and removed status: waiting-for-triage An issue we've not yet triaged labels Mar 17, 2025
@mp911de mp911de closed this as not planned Won't fix, can't repro, duplicate, stale Mar 17, 2025
@mipo256
Copy link
Contributor Author

mipo256 commented Mar 17, 2025

@mp911de Maybe we can write a section in the doc about it? I have not found any related documentation for this in Spring Data JDBC?

UPDATE: Sorry, I've completely missed the link to the doc yo've provided, thanks 😄

@mp911de
Copy link
Member

mp911de commented Mar 19, 2025

This documentation fragment comes from Commons. Feel free to submit a PR directly with some tweaked wording that Value Expressions do not support Bean Resolution but extensions must be provided through our SPI mechanism.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: declined A suggestion or change that we don't feel we should currently apply
Projects
None yet
Development

No branches or pull requests

3 participants