package at.spot.core.infrastructure.support.init;

import javax.annotation.Priority;

import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.EventListener;

import at.spot.core.infrastructure.exception.ModuleInitializationException;

@Configuration
@Priority(value = -1)
// needed to avoid some spring/hibernate problems
@EnableAutoConfiguration(exclude = { HibernateJpaAutoConfiguration.class })
public abstract class ModuleInit {

	boolean alreadyInitialized = false;

	/**
	 * This is a hook to customize the initialization process. It is called
	 * after {@link Bootstrap} has finished doing the basic initialization (load
	 * config properties and spring configuration).
	 */
	protected abstract void initialize() throws ModuleInitializationException;

	/**
	 * Called when the spring application context has been initialized.
	 * 
	 * @param event
	 * @throws ModuleInitializationException
	 */
	@EventListener
	protected void onApplicationEvent(final ApplicationReadyEvent event) throws ModuleInitializationException {
		if (!alreadyInitialized) {
			initialize();
			alreadyInitialized = true;
		}
	}
}

@@ -79,16 +79,65 @@
 ority;%0A%0A
+import org.springframework.beans.BeansException;%0A
 import o
@@ -353,16 +353,131 @@
 yEvent;%0A
+import org.springframework.context.ApplicationContext;%0Aimport org.springframework.context.ApplicationContextAware;%0A
 import o
@@ -863,12 +863,107 @@
 nit 
-%7B%0A%0A%09
+implements ApplicationContextAware %7B%0A%0A%09protected ApplicationContext applicationContext;%0A%09protected 
 bool
@@ -1076,18 +1076,18 @@
 lled
-%0A%09 *
  after
+%0A%09 *
  %7B@l
@@ -1154,19 +1154,19 @@
 load
-%0A%09 *
  config
+%0A%09 *
  pro
@@ -1632,11 +1632,258 @@
 ;%0A%09%09%7D%0A%09%7D
+%0A%0A%09@Override%0A%09public void setApplicationContext(ApplicationContext applicationContext) throws BeansException %7B%0A%09%09this.applicationContext = applicationContext;%0A%09%7D%0A%0A%09public ApplicationContext getApplicationContext() %7B%0A%09%09return applicationContext;%0A%09%7D
 %0A%7D%0A

make moduleinit context aware