spring-data-mongodb icon indicating copy to clipboard operation
spring-data-mongodb copied to clipboard

Can't (still) use properties in `@Indexed#expireAfter`

Open gbaso opened this issue 6 months ago • 1 comments

Following #4672, #2369 and Spring Data 2024.0 Release, I expected to be able to use property placeholders in @Indexed#expireAfter.

However, this is still not possible. SpEL expressions #{...} work, as well as bean references #{@bean.method()}, but using properties ${...} results in an exception: '${ttl}' is not a valid duration, cannot detect any known style.

Minimal sample: https://github.com/gbaso/spring-data-mongodb-ttl.

gbaso avatar May 23 '25 07:05 gbaso

thanks for the heads up, seems we'd need to obtain the ValueEvaluationContext in MongoPersistentEntityIndexResolver:663 instead of just the EvaluationContext.

christophstrobl avatar May 23 '25 07:05 christophstrobl

Hello, if no one is currently working on this issue, may I give it a try?

I’m planning to create a new method getValueEvaluationContextForProperty that returns a ValueEvaluationContext, as suggested by @christophstrobl

I will also add a test to confirm that the issue is resolved.

sangbeenmoon avatar Aug 16 '25 11:08 sangbeenmoon