ControllerAdviceBean#findAnnotatedBeans
~v5.0.9.RELEASE
v5.0.9.RELEASE 까지는 enhanced for 로 구성이 되어 있었다.
package org.springframework.web.method;
public class ControllerAdviceBean implements Ordered {
// ...
/**
* Find the names of beans annotated with
* {@linkplain ControllerAdvice @ControllerAdvice} in the given
* ApplicationContext and wrap them as {@code ControllerAdviceBean} instances.
*/
public static List<ControllerAdviceBean> findAnnotatedBeans(ApplicationContext applicationContext) {
List<ControllerAdviceBean> beans = new ArrayList<>();
for (String name : BeanFactoryUtils.beanNamesForTypeIncludingAncestors(applicationContext, Object.class)) {
if (applicationContext.findAnnotationOnBean(name, ControllerAdvice.class) != null) {
beans.add(new ControllerAdviceBean(name, applicationContext));
}
}
return beans;
}
v5.1.0.RELEASE
그러더니 5.1.0부터 stream으로 바뀌었다.
커미터: Rossen Stoyanchev at 2018-06-07
[SPR-16336] Extract HandlerTypePredicate from ControllerAdviceBean
public class ControllerAdviceBean implements Ordered {
// ...
public static List<ControllerAdviceBean> findAnnotatedBeans(ApplicationContext context) {
return Arrays.stream(BeanFactoryUtils.beanNamesForTypeIncludingAncestors(context, Object.class))
.filter(name -> context.findAnnotationOnBean(name, ControllerAdvice.class) != null)
.map(name -> new ControllerAdviceBean(name, context))
.collect(Collectors.toList());
}
v5.2.0.RELEASE
하지만 2019년 6월 21일 Sam Brannen에 의해 다시 바뀌었다는...
커밋 로그가 "Avoid use of Stream API in ControllerAdviceBean" 이다.
public class ControllerAdviceBean implements Ordered {
// ..
public static List<ControllerAdviceBean> findAnnotatedBeans(ApplicationContext context) {
List<ControllerAdviceBean> adviceBeans = new ArrayList<>();
for (String name : BeanFactoryUtils.beanNamesForTypeIncludingAncestors(context, Object.class)) {
ControllerAdvice controllerAdvice = context.findAnnotationOnBean(name, ControllerAdvice.class);
if (controllerAdvice != null) {
// Use the @ControllerAdvice annotation found by findAnnotationOnBean()
// in order to avoid a subsequent lookup of the same annotation.
adviceBeans.add(new ControllerAdviceBean(name, context, controllerAdvice));
}
}
OrderComparator.sort(adviceBeans);
return adviceBeans;
}
피보탈도 스트림 API를 지양하고 있다는 느낌을 받았다.
'Programing > Framework' 카테고리의 다른 글
[Sonarqube] Spring 기본 테스트 (0) | 2019.12.12 |
---|---|
[Spring] Bean 생성시 필드주입 시점은? (0) | 2019.10.17 |
[Spring] 스프링 프레임워크 개요 (0) | 2019.09.08 |
[Spring] MockRestServiceServer를 이용한 RestTemplate 테스트 (0) | 2019.08.09 |
[Spring] RestClientException 예외 정리 (0) | 2019.07.24 |