Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package org.sparta.springwebutils;
 
 import java.util.Map;
 
Utility class for handling with Spring context loading

Author(s):
Daniel Conde Diehl – Sparta Java Team History: May 21, 2014 - Daniel Conde Diehl - Creation
 
public class SpringContextUtils {

Loads a context from a XML and inject all objects in the Map

Parameters:
xmlPath Path for the xml applicationContext
extraBeans Extra beans for being injected
Returns:
ApplicationContext generated
	public static ApplicationContext contextMergedBeans(String xmlPathMap<String, ?> extraBeans) {
		//new empty context
		DefaultListableBeanFactory parentBeanFactory = new DefaultListableBeanFactory();  
		//Injection of the new beans in the context
		for (String key : extraBeans.keySet()) {
			parentBeanFactory.registerSingleton(keyextraBeans.get(key));
		}
		//loads the xml and add definitions in the context
		GenericApplicationContext parentContext = new GenericApplicationContext(parentBeanFactory);
		XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(parentContext);
		xmlReader.loadBeanDefinitions(xmlPath);
		//refreshed the context to create class and make autowires
		parentContext.refresh();
		//return the created context
		return parentContext;
	}
New to GrepCode? Check out our FAQ X