I am trying to use the SpEL to load the same Document into different collections based on some rules that i have 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 the provider bean that should provide the collection name:
@Component("mySpecialProvider")
public class MySpecialProvider {
public String getTargetCollectionName() {
// Thread local magic goes in bellow
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 should be generated by the provider i get the following stacktrace:
org.springframework.expression.spel.SpelEvaluationException: EL1057E:(pos 1): No bean resolver registered in the context to resolve access to bean 'mySpecialProvider'
I also tried making the spring component ApplicationContextAware but still no luck.