use of cn.taketoday.web.handler.ViewControllerHandlerAdapter in project today-framework by TAKETODAY.
the class WebApplicationLoader method configureHandlerAdapter.
/**
* Configure {@link HandlerAdapter}
*
* @param adapters {@link HandlerAdapter}s
* @param mvcConfiguration {@link WebMvcConfiguration}
*/
protected void configureHandlerAdapter(List<HandlerAdapter> adapters, WebMvcConfiguration mvcConfiguration) {
// 先看有的
DispatcherHandler obtainDispatcher = obtainDispatcher();
HandlerAdapter[] handlerAdapters = obtainDispatcher.getHandlerAdapters();
if (handlerAdapters != null) {
Collections.addAll(adapters, handlerAdapters);
}
// 添加默认的
adapters.add(new RequestHandlerAdapter(Ordered.HIGHEST_PRECEDENCE));
WebApplicationContext context = obtainApplicationContext();
// ViewControllerHandlerRegistry must configured
ViewControllerHandlerRegistry viewControllerRegistry = context.getBean(ViewControllerHandlerRegistry.class);
if (viewControllerRegistry != null) {
ViewControllerHandlerAdapter bean = context.getBean(ViewControllerHandlerAdapter.class);
if (bean == null) {
ViewControllerHandlerAdapter viewControllerHandlerAdapter = null;
for (HandlerAdapter adapter : adapters) {
if (adapter instanceof ViewControllerHandlerAdapter) {
viewControllerHandlerAdapter = (ViewControllerHandlerAdapter) adapter;
break;
}
}
if (viewControllerHandlerAdapter == null) {
adapters.add(new ViewControllerHandlerAdapter(Ordered.HIGHEST_PRECEDENCE));
}
}
}
// 排序
sort(adapters);
// apply request handler
obtainDispatcher.setHandlerAdapters(adapters.toArray(new HandlerAdapter[adapters.size()]));
}
Aggregations