Created
October 24, 2014 10:22
-
-
Save namuan/b30759e171afc7b34d8c to your computer and use it in GitHub Desktop.
Lookup all classes implementing a particular interface
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.springframework.beans.factory.config.BeanDefinition | |
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider | |
import org.springframework.core.type.filter.AssignableTypeFilter | |
import com.imon.basepackage.StatusCode.* | |
final ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false) | |
provider.addIncludeFilter(new AssignableTypeFilter(StatusCode.class)) | |
final Set<BeanDefinition> components = provider.findCandidateComponents("com.imon.basepackage") | |
println components.collect { BeanDefinition bd -> | |
Class cls = Class.forName(bd.getBeanClassName(), true, Thread.currentThread().contextClassLoader) | |
cls.values() | |
}.flatten { StatusCode code -> | |
[name: code.name(), httpCode: code.getHttpCode(), ('api-code'): code.getStatusCode(), ('message'): code.getStatusMessage()] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment