Example usage for org.springframework.web.context.support StaticWebApplicationContext registerSingleton

List of usage examples for org.springframework.web.context.support StaticWebApplicationContext registerSingleton

Introduction

In this page you can find the example usage for org.springframework.web.context.support StaticWebApplicationContext registerSingleton.

Prototype

public void registerSingleton(String name, Class<?> clazz) throws BeansException 

Source Link

Document

Register a singleton bean with the underlying bean factory.

Usage

From source file:com.javaetmoi.core.mvc.tag.TestHtml5InputTag.java

protected MockPageContext createPageContext() {
    MockServletContext sc = new MockServletContext();
    StaticWebApplicationContext wac = new StaticWebApplicationContext();
    wac.setServletContext(sc);// ww  w .jav  a 2s.c  om
    wac.setNamespace("test");
    wac.registerSingleton("validator",
            org.springframework.validation.beanvalidation.LocalValidatorFactoryBean.class);
    wac.refresh();

    MockHttpServletRequest request = new MockHttpServletRequest(sc);
    MockHttpServletResponse response = new MockHttpServletResponse();
    request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
    LocaleResolver lr = new AcceptHeaderLocaleResolver();
    request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, lr);
    ThemeResolver tr = new FixedThemeResolver();
    request.setAttribute(DispatcherServlet.THEME_RESOLVER_ATTRIBUTE, tr);
    request.setAttribute(DispatcherServlet.THEME_SOURCE_ATTRIBUTE, wac);

    return new MockPageContext(sc, request, response);
}