I am using Spring Data for MongoDB and I need to be able to configure collection at runtime.
My repository is defined as:
@Repository
public interfac
You can solve this problem by just using SPeL:
@Document(collection = "#{environment.getProperty('mongo.event.collection')}")
public class EventData implements Serializable {
...
}
Update Spring 5.x:
Since Spring 5.x or so you need an additional @ before environment:
@Document(collection = "#{@environment.getProperty('mongo.event.collection')}")
public class EventData implements Serializable {
...
}