Package com.aquima.web.util
Class ApplicationContextUtils
java.lang.Object
com.aquima.web.util.ApplicationContextUtils
Utility functions related to application contexts.
- Since:
- 10.0
- Author:
- Petru Galanton
-
Method Summary
Modifier and TypeMethodDescriptiongetNonScopedTargetBeansWithAnnotation
(org.springframework.context.ApplicationContext ctx, Class<? extends Annotation> annotationType) Helper method to find all non scoped target beans whoseClass
has the suppliedAnnotation
type, returning a Map of bean names with corresponding bean instances.
-
Method Details
-
getNonScopedTargetBeansWithAnnotation
public static Map<String,Object> getNonScopedTargetBeansWithAnnotation(org.springframework.context.ApplicationContext ctx, Class<? extends Annotation> annotationType) Helper method to find all non scoped target beans whoseClass
has the suppliedAnnotation
type, returning a Map of bean names with corresponding bean instances.ListableBeanFactory.getBeans* methods are able to look up any beans, even both the proxy and the target variant of a scoped bean. The advised workaround is either check getBeanDefinition(candidateName).isAutowireCandidate() and skip non-autowire beans that way or simply check for beanName.startsWith(ScopedProxyUtils.TARGET_NAME_PREFIX) (which is a supported way of detecting generated scoped target beans).
See also:- AQ-10369 Filter scoped target beans when using getBeansWithAnnotation()
- https://jira.spring.io/browse/SPR-14887
- Parameters:
ctx
- the application context to get the annotated beans fromannotationType
- the type of annotation to look for- Returns:
- a Map with the matching beans, containing the bean names as keys and the corresponding bean instances as values
-