I need to access current locale in Spring Repository using SpEL.
I have next Repository
:
@Repository
public interface RoomRepository extends JpaRepository<Room, Long> {
@Query(..."left join rc.roomClassTranslations rct on rct.language = ?#{SpEL expression})
List<RoomDTO> findAllRooms(Sort sort);
}
I tried several expressions but none of them worked.
#{@localeResolver.resolveLocale(#httpServletRequest).toLanguageTag()} "...)
In this expression httpServletRequest is null, if I change it to @httpServletRequest
, it will give an error that no bean is found. I also tried to rewrite it like this
#{LocaleContextHolder.getLocale().toLanguageTag()}
this will give next error:
EL1011E: Method call: Attempted to call method getLocale() on null context object.
So how to access current locale in SpEL expression?