Skip to content

Please provide example for using ReactiveEvaluationContextProvider #576

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

Closed
RobertHeim opened this issue Apr 10, 2021 · 1 comment
Closed
Labels
for: stackoverflow A question that's better suited to stackoverflow.com

Comments

@RobertHeim
Copy link

RobertHeim commented Apr 10, 2021

As I notice from the blog entry it should be possible to put stuff on the context for SpEL expressions, but I was not able to implement it.

@Configuration
class MyConfig {
  class X : EvaluationContextExtension{
    override fun getRootObject(): Any? {
      return "de"
    }
    override fun getExtensionId(): String {
      return "myExtension"
    }
  }

  class Y : ReactiveEvaluationContextExtension {
    override fun getExtensionId(): String {
      return "myExtension"
    }

    override fun getExtension(): Mono<out EvaluationContextExtension> {
      return  Mono.just(X())
    }
  }
  @Bean
  fun reactiveEvaluationContextExtension() : ReactiveEvaluationContextExtension? {
    return Y()
  }
}

When using it in a @Query like this:

interface TaskRepository : CoroutineCrudRepository<Task, Long> {
  @Query("SELECT * FROM task t WHERE t.locale = ?#{myExtension}")
  fun findWithLocale(): Flow<Task>
}

I see

EL1008E: Property or field 'myExtension' cannot be found on object of type 'java.lang.Object[]' - maybe not public or not valid?

In the end I would like to access the request's locale without putting it as a parameter to all controllers and services, e.g.

@Query("... WHERE tl10n.locale = ?#{locale.language}"
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Apr 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: stackoverflow A question that's better suited to stackoverflow.com
Projects
None yet
Development

No branches or pull requests

3 participants