![JAR search and dependency download from the Maven repository](/logo.png)
com.lordofthejars.nosqlunit.util.SpringUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of nosqlunit-marklogic Show documentation
Show all versions of nosqlunit-marklogic Show documentation
NoSQLUnit adapter for MarkLogic
The newest version!
package com.lordofthejars.nosqlunit.util;
import org.springframework.context.ApplicationContext;
import java.util.Map;
import static ch.lambdaj.collection.LambdaCollections.with;
import static org.hamcrest.CoreMatchers.anything;
public abstract class SpringUtils {
private SpringUtils() {
//hidden constructor
}
/**
* Search recursively in current and parent applicationContext's for Bean of Type T
*
* @param applicationContext Spring application context to start searching from
* @param aClass Class type of bean to search
* @param Type of bean to search
* @return first matched bean found
*/
public static T getBeanOfType(ApplicationContext applicationContext, Class aClass) {
Map beansOfType;
do {
beansOfType = applicationContext.getBeansOfType(aClass);
if (beansOfType != null && beansOfType.size() > 0) {
return with(beansOfType).values().first(anything());
}
applicationContext = applicationContext.getParent();
}
while (applicationContext != null);
return null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy