I am trying to use SpEL to upload the same document to different collections based on specific rules that I defined.
So, to start with what I have:
- first of all, the document:
@Document(collection = "#{@mySpecialProvider.getTargetCollectionName()}")
public class MongoDocument {
// some random fields go in
}
-second I have a bean provider that should provide a collection name:
@Component("mySpecialProvider")
public class MySpecialProvider {
public String getTargetCollectionName() {
String targetCollectionName = (String) RequestLocalContext.getFromLocalContext("targetCollectionName");
if (targetCollectionName == null) {
targetCollectionName = "defaultCollection";
}
return targetCollectionName;
}
}
The problem is that when I try to insert a document into a specific collection that needs to be generated by the provider, I get the following stack:
org.springframework.expression.spel.SpelEvaluationException: EL1057E: (pos 1): no bean resolver registered in context to allow access to bean 'mySpecialProvider'
I also tried making the spring component ApplicationContextAware , but still no luck.