use of cn.taketoday.web.registry.ViewControllerHandlerRegistry 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()]));
}
use of cn.taketoday.web.registry.ViewControllerHandlerRegistry in project today-framework by TAKETODAY.
the class WebApplicationLoader method configViewControllerHandlerRegistry.
/**
* Initialize framework.
*
* @throws Throwable if any Throwable occurred
*/
protected ViewControllerHandlerRegistry configViewControllerHandlerRegistry(@Nullable ViewControllerHandlerRegistry registry) throws Throwable {
// find the configure file
log.info("TODAY WEB Framework Is Looking For ViewController Configuration File.");
String webMvcConfigLocation = getWebMvcConfigLocation();
if (StringUtils.isEmpty(webMvcConfigLocation)) {
log.info("Configuration File does not exist.");
return registry;
}
if (registry == null) {
WebApplicationContext context = obtainApplicationContext();
context.unwrap(BeanDefinitionRegistrar.class).registerBean(ViewControllerHandlerRegistry.DEFAULT_BEAN_NAME, ViewControllerHandlerRegistry.class);
registry = context.getBean(ViewControllerHandlerRegistry.DEFAULT_BEAN_NAME, ViewControllerHandlerRegistry.class);
}
registry.configure(webMvcConfigLocation);
return registry;
}
Aggregations