public <T> Collection<T> find(Class<T> clazz, Object context) {
Collection<T> result = new ArrayList<T>();
// use the Spring API to obtain the WebApplicationContext
WebApplicationContext applicationContext = null;
if (context instanceof ServletContext) {
applicationContext = WebApplicationContextUtils.getWebApplicationContext((ServletContext) context);
}
if (applicationContext == null) {
applicationContext = ContextLoader.getCurrentWebApplicationContext();
}
// may be null if Spring hasn't started yet
if (applicationContext != null) {
// ask spring about beans of this type
result.addAll(applicationContext.getBeansOfType(clazz).values());
}
return result;