user1676688
user1676688

Reputation: 424

Evaluation context not correctly set for @Document in Spring 5.x / Spring boot 2.1.6

I am writing a Spring boot application with latest Spring boot 2.1.6 release. There was an issue earlier, which has been discussed both on SO as well as Spring's bug tracker where the Spring EL context did not have access to beans.

This was supposed to have been resolved in Spring 4.x releases. However, I am facing the same problem

References:

  1. SO thread 1
  2. SO thread 2
  3. Spring Data Bug 1043
  4. Spring Data Bug 525
  5. Spring Data Bug 1874

I have tried most of the solutions that were suggested before the actual fix was put in as well.

Right now my code has the annotation like this -

@Document("#{mongoCollectionNameResolver.getCollectionName('BANK')}")
//@Document("BANK")
public class Bank {
}

I have verified that the bean is getting correctly created with the name mentioned in the expression.

I just wanted to ask the community if I am supposed to do anything more for Spring 5.x that I am missing before I reopen the bug / open a new bug with Spring data mongo

Upvotes: 1

Views: 240

Answers (1)

M. Deinum
M. Deinum

Reputation: 124441

When referring to beans with names from SpEL they need to be prefixed @ (see the Spring Reference Guide). That being said this means your SpEL expression is wrong.

It should be #{@mongoCollectionNameResolver.getCollectionName('BANK')}.

Upvotes: 1

Related Questions