package org.radarcns.management.domain.support;

import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * Created by dverbeec on 17/11/2017.
 */
@Component
public class AutowireHelper implements ApplicationContextAware {
    private static final AutowireHelper INSTANCE = new AutowireHelper();
    private static ApplicationContext applicationContext;

    private AutowireHelper() {
    }

    /**
     * Tries to autowire the specified instance of the class if one of the specified beans which need to be autowired
     * are null.
     *
     * @param classToAutowire the instance of the class which holds @Autowire annotations
     * @param beansToAutowireInClass the beans which have the @Autowire annotation in the specified {#classToAutowire}
     */
    public static void autowire(Object classToAutowire, Object... beansToAutowireInClass) {
        for (Object bean : beansToAutowireInClass) {
            if (bean == null) {
                applicationContext.getAutowireCapableBeanFactory().autowireBean(classToAutowire);
                return;
            }
        }
    }

    @Override
    public void setApplicationContext(final ApplicationContext applicationContext) {
        AutowireHelper.applicationContext = applicationContext;
    }

    /**
     * @return the singleton instance.
     */
    public static AutowireHelper getInstance() {
        return INSTANCE;
    }
}

@@ -219,40 +219,109 @@
  * C
-reated by dverbeec on 17/11/2017
+lass to inject dependencies into classes that do not support Autowire, such as JPA event%0A * listeners
 .%0A *
@@ -672,16 +672,23 @@
 ns which
+%0A     *
  need to
@@ -700,23 +700,16 @@
 utowired
-%0A     *
  are nul
@@ -893,24 +893,61 @@
 ation in the
+%0A     *                              
  specified %7B

Update JavaDoc of AutowireHelper