Search in sources :

Example 1 with DefaultRequestToViewNameTranslator

use of org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator in project spring-framework by spring-projects.

the class StandaloneMockMvcBuilder method registerMvcSingletons.

private void registerMvcSingletons(StubWebApplicationContext wac) {
    StandaloneConfiguration config = new StandaloneConfiguration();
    config.setApplicationContext(wac);
    ServletContext sc = wac.getServletContext();
    wac.addBeans(this.controllers);
    wac.addBeans(this.controllerAdvice);
    FormattingConversionService mvcConversionService = config.mvcConversionService();
    wac.addBean("mvcConversionService", mvcConversionService);
    ResourceUrlProvider resourceUrlProvider = config.mvcResourceUrlProvider();
    wac.addBean("mvcResourceUrlProvider", resourceUrlProvider);
    ContentNegotiationManager mvcContentNegotiationManager = config.mvcContentNegotiationManager();
    wac.addBean("mvcContentNegotiationManager", mvcContentNegotiationManager);
    Validator mvcValidator = config.mvcValidator();
    wac.addBean("mvcValidator", mvcValidator);
    RequestMappingHandlerMapping hm = config.getHandlerMapping(mvcConversionService, resourceUrlProvider);
    if (sc != null) {
        hm.setServletContext(sc);
    }
    hm.setApplicationContext(wac);
    hm.afterPropertiesSet();
    wac.addBean("requestMappingHandlerMapping", hm);
    RequestMappingHandlerAdapter ha = config.requestMappingHandlerAdapter(mvcContentNegotiationManager, mvcConversionService, mvcValidator);
    if (sc != null) {
        ha.setServletContext(sc);
    }
    ha.setApplicationContext(wac);
    ha.afterPropertiesSet();
    wac.addBean("requestMappingHandlerAdapter", ha);
    wac.addBean("handlerExceptionResolver", config.handlerExceptionResolver(mvcContentNegotiationManager));
    wac.addBeans(initViewResolvers(wac));
    wac.addBean(DispatcherServlet.LOCALE_RESOLVER_BEAN_NAME, this.localeResolver);
    wac.addBean(DispatcherServlet.THEME_RESOLVER_BEAN_NAME, new FixedThemeResolver());
    wac.addBean(DispatcherServlet.REQUEST_TO_VIEW_NAME_TRANSLATOR_BEAN_NAME, new DefaultRequestToViewNameTranslator());
    this.flashMapManager = new SessionFlashMapManager();
    wac.addBean(DispatcherServlet.FLASH_MAP_MANAGER_BEAN_NAME, this.flashMapManager);
    extendMvcSingletons(sc).forEach(wac::addBean);
}
Also used : ContentNegotiationManager(org.springframework.web.accept.ContentNegotiationManager) FixedThemeResolver(org.springframework.web.servlet.theme.FixedThemeResolver) DefaultRequestToViewNameTranslator(org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator) ServletContext(jakarta.servlet.ServletContext) MockServletContext(org.springframework.mock.web.MockServletContext) SessionFlashMapManager(org.springframework.web.servlet.support.SessionFlashMapManager) RequestMappingHandlerMapping(org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping) FormattingConversionService(org.springframework.format.support.FormattingConversionService) DefaultFormattingConversionService(org.springframework.format.support.DefaultFormattingConversionService) RequestMappingHandlerAdapter(org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter) Validator(org.springframework.validation.Validator) ResourceUrlProvider(org.springframework.web.servlet.resource.ResourceUrlProvider)

Aggregations

ServletContext (jakarta.servlet.ServletContext)1 DefaultFormattingConversionService (org.springframework.format.support.DefaultFormattingConversionService)1 FormattingConversionService (org.springframework.format.support.FormattingConversionService)1 MockServletContext (org.springframework.mock.web.MockServletContext)1 Validator (org.springframework.validation.Validator)1 ContentNegotiationManager (org.springframework.web.accept.ContentNegotiationManager)1 RequestMappingHandlerAdapter (org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter)1 RequestMappingHandlerMapping (org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping)1 ResourceUrlProvider (org.springframework.web.servlet.resource.ResourceUrlProvider)1 SessionFlashMapManager (org.springframework.web.servlet.support.SessionFlashMapManager)1 FixedThemeResolver (org.springframework.web.servlet.theme.FixedThemeResolver)1 DefaultRequestToViewNameTranslator (org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator)1