docs: @SuppressWarnings("unchecked")
      @Override
      public void run(Class<? extends Object> toRun, JobManager handler, Map<String, String> handlerParameters)
      {
          // initialize the spring context with all requested classes on first boot -
          // and only on first boot: the Spring context cannot be refreshed multiple times.
          if (!refreshed)
          {
              synchronized (AnnotationSpringContextBootstrapHandler.class)
              {
                  if (!refreshed)
                  {
                      // Add the different elements to the context path
                      if (handlerParameters.containsKey("beanNameGenerator"))
                      {
                          Class<? extends BeanNameGenerator> clazz;
                          try
                          {
                              clazz = (Class<? extends BeanNameGenerator>) AnnotationSpringContextBootstrapHandler.class.getClassLoader()
                                      .loadClass(handlerParameters.get("beanNameGenerator"));
                          }
                          catch (ClassNotFoundException e)
                          {
                              throw new RuntimeException("The handler beanNameGenerator class [" + handlerParameters.get("beanNameGenerator")
                                      + "] cannot be found.", e);
                          }
  
                          BeanNameGenerator generator;
                          try
                          {
                              generator = clazz.newInstance();
                          }
                          catch (Exception e)
                          {
                              throw new RuntimeException("The handler beanNameGenerator class [" + handlerParameters.get("beanNameGenerator")
                                      + "] was found but cannot be instantiated. Check it has a no-arguments constructor.", e);
                          }
  
                          ctx.setBeanNameGenerator(generator);
                      }
  
                      if (handlerParameters.containsKey("contextDisplayName"))
                      {
                          ctx.setDisplayName(handlerParameters.get("contextDisplayName"));
                      }
  
                      if (handlerParameters.containsKey("contextId"))
                      {
                          ctx.setId(handlerParameters.get("contextId"));
                      }
  
                      if (handlerParameters.containsKey("allowCircularReferences"))
                      {
                          boolean allow = Boolean.parseBoolean(handlerParameters.get("allowCircularReferences"));
                          ctx.setAllowCircularReferences(allow);
                      }
  
                      if (handlerParameters.containsKey("additionalScan"))
                      {
                          ctx.scan(handlerParameters.get("additionalScan").split(","));
                      }
                      else
                      {
                          ctx.register(toRun);
                      }
  
                      // Create a holder for the parameters.
                      BeanDefinition def = new RootBeanDefinition(HashMap.class);
                      def.setScope(THREAD_SCOPE_NAME);
                      ctx.registerBeanDefinition("runtimeParameters", def);
  
                      // This is a factory to retrieve the JobManager. We cannot just inject the JM, as it is created at runtime, long after
                      // the context has been created!
                      def = new RootBeanDefinition(JobManagerProvider.class);
                      def.setScope(BeanDefinition.SCOPE_SINGLETON);
                      ctx.registerBeanDefinition("jobManagerProvider", def);
  
                      // It would however be possible to use a lazy bean injection. But this would require the user to put @Lazy everywhere,
                      // or else the result is null... Too fragile. The provider/factory pattern above does the same thing and forces the user
                      // to do a lazy call.
                      // def = new RootBeanDefinition(JobManager.class);
                      // def.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
                      // def.setLazyInit(true);
                      // def.setFactoryBeanName("jobManagerProvider");
                      // def.setFactoryMethodName("getObject");
                      // ctx.registerBeanDefinition("jobManager", def);
  
                      // Go: this initializes the context
                      ctx.refresh();
                      refreshed = true;
                  }
              }
          }
      }