@Override
  public void afterPropertiesSet() throws Exception {
    db = mongo.getDb();

    /**
     * add auditing features to given entities. after save of given entities, put the entity into
     * according history collection too
     *
     * <p>entities that should have history entires should be annotated with {@link Audited}
     */
    for (GrailsClass domainClass :
        grailsApplication.getArtefacts(MongoDomainClassArtefactHandler.TYPE)) {
      if (domainClass instanceof GrailsDomainClass
          && domainClass.getClazz().getAnnotation(Audited.class) != null)
        auditClass(domainClass.getClazz());
    }

    // init audit processor
    try {
      Object mongodbAuditProcessor =
          grailsApplication.getMainContext().getBean("mongodbAuditProcessor");
      if (mongodbAuditProcessor instanceof MongodbAuditProcessor)
        this.auditProcessor = (MongodbAuditProcessor) mongodbAuditProcessor;
    } catch (BeansException ignore) {
      // do not care if not defined
    }
  }
 /**
  * Add class to watched classes for auditing Not thread safe. Call this method once during app
  * initialization
  *
  * @param auditClass
  */
 public void auditClass(Class auditClass) {
   MappedClass mappedClass = mongo.getMorphia().getMapper().getMappedClass(auditClass);
   if (mappedClass != null) {
     watchedClasses.put(auditClass, mappedClass.getCollectionName() + "History");
   }
 }