java类org.springframework.web.context.support.XmlWebApplicationContext的实例源码

WiringTests.java 文件源码 项目:springboot-shiro-cas-mybatis 阅读 23 收藏 0 点赞 0 评论 0
@Before
public void setUp() {
    applicationContext = new XmlWebApplicationContext();
    applicationContext.setConfigLocations(
            "file:src/main/webapp/WEB-INF/cas-management-servlet.xml",
            "file:src/main/webapp/WEB-INF/managementConfigContext.xml",
    "file:src/main/webapp/WEB-INF/spring-configuration/*.xml");
    applicationContext.setServletContext(new MockServletContext(new ResourceLoader() {
        @Override
        public Resource getResource(final String location) {
            return new FileSystemResource("src/main/webapp" + location);
        }

        @Override
        public ClassLoader getClassLoader() {
            return getClassLoader();
        }
    }));
    applicationContext.refresh();
}
WiringTests.java 文件源码 项目:springboot-shiro-cas-mybatis 阅读 32 收藏 0 点赞 0 评论 0
@Before
public void setUp() {
    applicationContext = new XmlWebApplicationContext();
    applicationContext.setConfigLocations(
            "classpath:/webappContext.xml",
            "file:src/main/webapp/WEB-INF/cas-servlet.xml",
            "file:src/main/webapp/WEB-INF/deployerConfigContext.xml",
    "file:src/main/webapp/WEB-INF/spring-configuration/*.xml");
    applicationContext.setServletContext(new MockServletContext(new ResourceLoader() {
        @Override
        public Resource getResource(final String location) {
            return new FileSystemResource("src/main/webapp" + location);
        }

        @Override
        public ClassLoader getClassLoader() {
            return getClassLoader();
        }
    }));
    applicationContext.refresh();
}
WiringTests.java 文件源码 项目:springboot-shiro-cas-mybatis 阅读 35 收藏 0 点赞 0 评论 0
@Before
public void setUp() {
    applicationContext = new XmlWebApplicationContext();
    applicationContext.setConfigLocations(
            "classpath:/cas-management-servlet.xml",
            "classpath:/managementConfigContext.xml",
            "classpath:/spring-configuration/*.xml");
    applicationContext.setServletContext(new MockServletContext(new ResourceLoader() {
        @Override
        public Resource getResource(final String location) {
            return new FileSystemResource("src/main/webapp" + location);
        }

        @Override
        public ClassLoader getClassLoader() {
            return WiringTests.class.getClassLoader();
        }
    }));
    applicationContext.refresh();
}
WiringTests.java 文件源码 项目:springboot-shiro-cas-mybatis 阅读 29 收藏 0 点赞 0 评论 0
@Before
public void setUp() {
    applicationContext = new XmlWebApplicationContext();
    applicationContext.setConfigLocations(
            "file:src/main/webapp/WEB-INF/cas-servlet.xml",
            "file:src/main/webapp/WEB-INF/deployerConfigContext.xml",
    "file:src/main/webapp/WEB-INF/spring-configuration/*.xml");
    applicationContext.setServletContext(new MockServletContext(new ResourceLoader() {
        @Override
        public Resource getResource(final String location) {
            return new FileSystemResource("src/main/webapp" + location);
        }

        @Override
        public ClassLoader getClassLoader() {
            return getClassLoader();
        }
    }));
    applicationContext.refresh();
}
WiringTests.java 文件源码 项目:cas4.0.x-server-wechat 阅读 25 收藏 0 点赞 0 评论 0
@Before
public void setUp() {
    applicationContext = new XmlWebApplicationContext();
    applicationContext.setConfigLocations(new String[]{
            "file:src/main/webapp/WEB-INF/cas-servlet.xml",
            "file:src/main/webapp/WEB-INF/deployerConfigContext.xml",
    "file:src/main/webapp/WEB-INF/spring-configuration/*.xml"});
    applicationContext.setServletContext(new MockServletContext(new ResourceLoader() {
        @Override
        public Resource getResource(final String location) {
            return new FileSystemResource("src/main/webapp" + location);
        }

        @Override
        public ClassLoader getClassLoader() {
            return getClassLoader();
        }
    }));
    applicationContext.refresh();
}
WiringTests.java 文件源码 项目:cas4.0.x-server-wechat 阅读 22 收藏 0 点赞 0 评论 0
@Before
public void setUp() {
    applicationContext = new XmlWebApplicationContext();
    applicationContext.setConfigLocations(new String[]{
            "file:src/main/webapp/WEB-INF/cas-management-servlet.xml",
            "file:src/main/webapp/WEB-INF/managementConfigContext.xml",
    "file:src/main/webapp/WEB-INF/spring-configuration/*.xml"});
    applicationContext.setServletContext(new MockServletContext(new ResourceLoader() {
        @Override
        public Resource getResource(final String location) {
            return new FileSystemResource("src/main/webapp" + location);
        }

        @Override
        public ClassLoader getClassLoader() {
            return getClassLoader();
        }
    }));
    applicationContext.refresh();
}
WiringTests.java 文件源码 项目:cas-server-4.2.1 阅读 22 收藏 0 点赞 0 评论 0
@Before
public void setUp() {
    applicationContext = new XmlWebApplicationContext();
    applicationContext.setConfigLocations(
            "classpath:/webappContext.xml",
            "file:src/main/webapp/WEB-INF/cas-servlet.xml",
            "file:src/main/webapp/WEB-INF/deployerConfigContext.xml",
    "file:src/main/webapp/WEB-INF/spring-configuration/*.xml");
    applicationContext.setServletContext(new MockServletContext(new ResourceLoader() {
        @Override
        public Resource getResource(final String location) {
            return new FileSystemResource("src/main/webapp" + location);
        }

        @Override
        public ClassLoader getClassLoader() {
            return getClassLoader();
        }
    }));
    applicationContext.refresh();
}
WiringTests.java 文件源码 项目:cas-server-4.2.1 阅读 27 收藏 0 点赞 0 评论 0
@Before
public void setUp() {
    applicationContext = new XmlWebApplicationContext();
    applicationContext.setConfigLocations(
            "classpath:/cas-management-servlet.xml",
            "classpath:/managementConfigContext.xml",
            "classpath:/spring-configuration/*.xml");
    applicationContext.setServletContext(new MockServletContext(new ResourceLoader() {
        @Override
        public Resource getResource(final String location) {
            return new FileSystemResource("src/main/webapp" + location);
        }

        @Override
        public ClassLoader getClassLoader() {
            return WiringTests.class.getClassLoader();
        }
    }));
    applicationContext.refresh();
}
SimpleUrlHandlerMappingTests.java 文件源码 项目:spring4-understanding 阅读 18 收藏 0 点赞 0 评论 0
@Test
public void handlerBeanNotFound() throws Exception {
    MockServletContext sc = new MockServletContext("");
    XmlWebApplicationContext root = new XmlWebApplicationContext();
    root.setServletContext(sc);
    root.setConfigLocations(new String[] {"/org/springframework/web/servlet/handler/map1.xml"});
    root.refresh();
    XmlWebApplicationContext wac = new XmlWebApplicationContext();
    wac.setParent(root);
    wac.setServletContext(sc);
    wac.setNamespace("map2err");
    wac.setConfigLocations(new String[] {"/org/springframework/web/servlet/handler/map2err.xml"});
    try {
        wac.refresh();
        fail("Should have thrown NoSuchBeanDefinitionException");
    }
    catch (FatalBeanException ex) {
        NoSuchBeanDefinitionException nestedEx = (NoSuchBeanDefinitionException) ex.getCause();
        assertEquals("mainControlle", nestedEx.getBeanName());
    }
}
XmlWebApplicationContextTests.java 文件源码 项目:spring4-understanding 阅读 18 收藏 0 点赞 0 评论 0
@Test
@SuppressWarnings("resource")
public void withoutMessageSource() throws Exception {
    MockServletContext sc = new MockServletContext("");
    XmlWebApplicationContext wac = new XmlWebApplicationContext();
    wac.setParent(root);
    wac.setServletContext(sc);
    wac.setNamespace("testNamespace");
    wac.setConfigLocations(new String[] {"/org/springframework/web/context/WEB-INF/test-servlet.xml"});
    wac.refresh();
    try {
        wac.getMessage("someMessage", null, Locale.getDefault());
        fail("Should have thrown NoSuchMessageException");
    }
    catch (NoSuchMessageException ex) {
        // expected;
    }
    String msg = wac.getMessage("someMessage", null, "default", Locale.getDefault());
    assertTrue("Default message returned", "default".equals(msg));
}
ContextLoaderTests.java 文件源码 项目:spring4-understanding 阅读 27 收藏 0 点赞 0 评论 0
@Test
public void testContextLoaderListenerWithDefaultContext() {
    MockServletContext sc = new MockServletContext("");
    sc.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM,
            "/org/springframework/web/context/WEB-INF/applicationContext.xml " +
            "/org/springframework/web/context/WEB-INF/context-addition.xml");
    ServletContextListener listener = new ContextLoaderListener();
    ServletContextEvent event = new ServletContextEvent(sc);
    listener.contextInitialized(event);
    WebApplicationContext context = (WebApplicationContext) sc.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
    assertTrue("Correct WebApplicationContext exposed in ServletContext", context instanceof XmlWebApplicationContext);
    assertTrue(WebApplicationContextUtils.getRequiredWebApplicationContext(sc) instanceof XmlWebApplicationContext);
    LifecycleBean lb = (LifecycleBean) context.getBean("lifecycle");
    assertTrue("Has father", context.containsBean("father"));
    assertTrue("Has rod", context.containsBean("rod"));
    assertTrue("Has kerry", context.containsBean("kerry"));
    assertTrue("Not destroyed", !lb.isDestroyed());
    assertFalse(context.containsBean("beans1.bean1"));
    assertFalse(context.containsBean("beans1.bean2"));
    listener.contextDestroyed(event);
    assertTrue("Destroyed", lb.isDestroyed());
    assertNull(sc.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE));
    assertNull(WebApplicationContextUtils.getWebApplicationContext(sc));
}
SpringProfilesActivator.java 文件源码 项目:quartzdesk-executor 阅读 20 收藏 0 点赞 0 评论 0
@Override
public void initialize( XmlWebApplicationContext applicationContext )
{
  ConfigurableEnvironment env = applicationContext.getEnvironment();

  WorkDir workDir;
  try
  {
    workDir = new WorkDir( applicationContext.getServletContext() );
  }
  catch ( IOException e )
  {
    throw new ApplicationContextException( "Error obtaining QuartzDesk Executor work directory.", e );
  }

  String databaseProfile = getDatabaseProfile( workDir );

  String[] activeProfiles = new String[] { databaseProfile };

  log.info( "Activating Spring profiles: {}", Arrays.toString( activeProfiles ) );

  env.setActiveProfiles( activeProfiles );
}
LambdaHandler.java 文件源码 项目:aws-serverless-java-container 阅读 43 收藏 0 点赞 0 评论 0
public AwsProxyResponse handleRequest(AwsProxyRequest awsProxyRequest, Context context)
{
     if (!isinitialized) {
         isinitialized = true;
         try {
            XmlWebApplicationContext wc = new XmlWebApplicationContext();
            wc.setConfigLocation("classpath:/staticAppContext.xml");
             handler = SpringLambdaContainerHandler.getAwsProxyHandler(wc);
         } catch (ContainerInitializationException e) {
             e.printStackTrace();
             return null;
         }
     }
     AwsProxyResponse res = handler.proxy(awsProxyRequest, context);
     return res;
}
WiringTests.java 文件源码 项目:cas-server-webapp 阅读 22 收藏 0 点赞 0 评论 0
@Before
public void setUp() {
    applicationContext = new XmlWebApplicationContext();
    applicationContext.setConfigLocations(
            "file:src/main/webapp/WEB-INF/cas-servlet.xml",
            "file:src/main/webapp/WEB-INF/deployerConfigContext.xml",
    "file:src/main/webapp/WEB-INF/spring-configuration/*.xml");
    applicationContext.setServletContext(new MockServletContext(new ResourceLoader() {
        @Override
        public Resource getResource(final String location) {
            return new FileSystemResource("src/main/webapp" + location);
        }

        @Override
        public ClassLoader getClassLoader() {
            return getClassLoader();
        }
    }));
    applicationContext.refresh();
}
SpringWebApplicationInitializer.java 文件源码 项目:nbone 阅读 26 收藏 0 点赞 0 评论 0
/**
* <p>默认关闭<p>
* 加载spring mvc 统一调度器
* @param servletContext
*/
  protected void initDispatcherServlet(ServletContext servletContext){
    String enable  = servletContext.getInitParameter("enableDispatcherServlet");
    if(BooleanUtils.valueOf(enable)){
        //classpath*:/spring-mvc*.xml,/WEB-INF/spring-mvc*.xml
        XmlWebApplicationContext appContext = new XmlWebApplicationContext();
        appContext.setConfigLocation("classpath*:/spring/spring-mvc*.xml,/WEB-INF/spring/spring-mvc*.xml");


        ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", new DispatcherServlet(appContext));
        dispatcher.setLoadOnStartup(1);
        dispatcher.addMapping("/");

    }

  }
WiringTests.java 文件源码 项目:cas4.1.9 阅读 23 收藏 0 点赞 0 评论 0
@Before
public void setUp() {
    applicationContext = new XmlWebApplicationContext();
    applicationContext.setConfigLocations(
            "file:src/main/webapp/WEB-INF/cas-servlet.xml",
            "file:src/main/webapp/WEB-INF/deployerConfigContext.xml",
    "file:src/main/webapp/WEB-INF/spring-configuration/*.xml");
    applicationContext.setServletContext(new MockServletContext(new ResourceLoader() {
        @Override
        public Resource getResource(final String location) {
            return new FileSystemResource("src/main/webapp" + location);
        }

        @Override
        public ClassLoader getClassLoader() {
            return getClassLoader();
        }
    }));
    applicationContext.refresh();
}
WiringTests.java 文件源码 项目:cas4.1.9 阅读 27 收藏 0 点赞 0 评论 0
@Before
public void setUp() {
    applicationContext = new XmlWebApplicationContext();
    applicationContext.setConfigLocations(
            "file:src/main/webapp/WEB-INF/cas-management-servlet.xml",
            "file:src/main/webapp/WEB-INF/managementConfigContext.xml",
    "file:src/main/webapp/WEB-INF/spring-configuration/*.xml");
    applicationContext.setServletContext(new MockServletContext(new ResourceLoader() {
        @Override
        public Resource getResource(final String location) {
            return new FileSystemResource("src/main/webapp" + location);
        }

        @Override
        public ClassLoader getClassLoader() {
            return getClassLoader();
        }
    }));
    applicationContext.refresh();
}
DispatcherServletInitializer.java 文件源码 项目:communote-server 阅读 28 收藏 0 点赞 0 评论 0
private void createMainDispatcherServlet(ApplicationContext rootContext) {
    mainWebApplicationContext = new XmlWebApplicationContext();
    mainWebApplicationContext
            .setConfigLocation(getRequiredInitParameter("communoteWebContextConfigLocation"));
    mainWebApplicationContext.setParent(rootContext);
    // add ContextLoaderListener with web-ApplicationContext which publishes it under a
    // ServletContext attribute and closes it on shutdown. The former is required for
    // WebApplicationContextUtils which are used by DelegatingFilterProxy (spring security).
    // Closing is also done by dispatcher servlet's implementation of destroy method.
    this.servletContext.addListener(new ContextLoaderListener(mainWebApplicationContext));
    DispatcherServlet dispatcherServlet = new DispatcherServlet(mainWebApplicationContext);
    ServletRegistration.Dynamic addedServlet = this.servletContext.addServlet(
            getInitParameter("communoteServletName", "communote"), dispatcherServlet);
    addedServlet.setLoadOnStartup(1);
    addedServlet.addMapping(getRequiredInitParameter("communoteServletUrlPattern"));
    this.mainDispatcherServlet = dispatcherServlet;
}
SpringResourceLoader.java 文件源码 项目:kc-rice 阅读 18 收藏 0 点赞 0 评论 0
@Override
public void start() throws Exception {
    if(!isStarted()){
        LOG.info("Creating Spring context " + StringUtils.join(this.fileLocs, ","));
        if (parentSpringResourceLoader != null && parentContext != null) {
            throw new ConfigurationException("Both a parentSpringResourceLoader and parentContext were defined.  Only one can be defined!");
        }
        if (parentSpringResourceLoader != null) {
            parentContext = parentSpringResourceLoader.getContext();
        }

        if (servletContextcontext != null) {
            XmlWebApplicationContext lContext = new XmlWebApplicationContext();
            lContext.setServletContext(servletContextcontext);
            lContext.setParent(parentContext);
            lContext.setConfigLocations(this.fileLocs.toArray(new String[] {}));
            lContext.refresh();
            context = lContext;
        } else {
            this.context = new ClassPathXmlApplicationContext(this.fileLocs.toArray(new String[] {}), parentContext);
        }

        super.start();
    }
}
WiringTests.java 文件源码 项目:cas-4.0.1 阅读 22 收藏 0 点赞 0 评论 0
@Before
public void setUp() {
    applicationContext = new XmlWebApplicationContext();
    applicationContext.setConfigLocations(new String[]{
            "file:src/main/webapp/WEB-INF/cas-servlet.xml",
            "file:src/main/webapp/WEB-INF/deployerConfigContext.xml",
    "file:src/main/webapp/WEB-INF/spring-configuration/*.xml"});
    applicationContext.setServletContext(new MockServletContext(new ResourceLoader() {
        @Override
        public Resource getResource(final String location) {
            return new FileSystemResource("src/main/webapp" + location);
        }

        @Override
        public ClassLoader getClassLoader() {
            return getClassLoader();
        }
    }));
    applicationContext.refresh();
}
WiringTests.java 文件源码 项目:cas-4.0.1 阅读 45 收藏 0 点赞 0 评论 0
@Before
public void setUp() {
    applicationContext = new XmlWebApplicationContext();
    applicationContext.setConfigLocations(new String[]{
            "file:src/main/webapp/WEB-INF/cas-management-servlet.xml",
            "file:src/main/webapp/WEB-INF/managementConfigContext.xml",
    "file:src/main/webapp/WEB-INF/spring-configuration/*.xml"});
    applicationContext.setServletContext(new MockServletContext(new ResourceLoader() {
        @Override
        public Resource getResource(final String location) {
            return new FileSystemResource("src/main/webapp" + location);
        }

        @Override
        public ClassLoader getClassLoader() {
            return getClassLoader();
        }
    }));
    applicationContext.refresh();
}
InstallWizard.java 文件源码 项目:openmeetings 阅读 19 收藏 0 点赞 0 评论 0
@Override
protected void onSubmit() {
    try {
        ConnectionPropertiesPatcher.patch(getModelObject());
        XmlWebApplicationContext ctx = (XmlWebApplicationContext)getWebApplicationContext(Application.get().getServletContext());
        if (ctx == null) {
            form.error(new StringResourceModel("install.wizard.db.step.error.patch", InstallWizard.this).setParameters("Web context is NULL").getObject());
            log.error("Web context is NULL");
            return;
        }
        LocalEntityManagerFactoryBean emb = ctx.getBeanFactory().getBean(LocalEntityManagerFactoryBean.class);
        emb.afterPropertiesSet();
        dbType = getModelObject().getDbType();
    } catch (Exception e) {
        form.error(new StringResourceModel("install.wizard.db.step.error.patch", InstallWizard.this).setParameters(e.getMessage()).getObject());
        log.error("error while patching", e);
    }
}
WiringTests.java 文件源码 项目:p00 阅读 23 收藏 0 点赞 0 评论 0
@Before
public void setUp() {
    applicationContext = new XmlWebApplicationContext();
    applicationContext.setConfigLocations(new String[]{
            "file:src/main/webapp/WEB-INF/cas-servlet.xml",
            "file:src/main/webapp/WEB-INF/deployerConfigContext.xml",
    "file:src/main/webapp/WEB-INF/spring-configuration/*.xml"});
    applicationContext.setServletContext(new MockServletContext(new ResourceLoader() {
        @Override
        public Resource getResource(final String location) {
            return new FileSystemResource("src/main/webapp" + location);
        }

        @Override
        public ClassLoader getClassLoader() {
            return getClassLoader();
        }
    }));
    applicationContext.refresh();
}
WiringTests.java 文件源码 项目:p00 阅读 26 收藏 0 点赞 0 评论 0
@Before
public void setUp() {
    applicationContext = new XmlWebApplicationContext();
    applicationContext.setConfigLocations(new String[]{
            "file:src/main/webapp/WEB-INF/cas-management-servlet.xml",
            "file:src/main/webapp/WEB-INF/managementConfigContext.xml",
    "file:src/main/webapp/WEB-INF/spring-configuration/*.xml"});
    applicationContext.setServletContext(new MockServletContext(new ResourceLoader() {
        @Override
        public Resource getResource(final String location) {
            return new FileSystemResource("src/main/webapp" + location);
        }

        @Override
        public ClassLoader getClassLoader() {
            return getClassLoader();
        }
    }));
    applicationContext.refresh();
}
WiringTests.java 文件源码 项目:cas-server-4.0.1 阅读 22 收藏 0 点赞 0 评论 0
@Before
public void setUp() {
    applicationContext = new XmlWebApplicationContext();
    applicationContext.setConfigLocations(new String[]{
            "file:src/main/webapp/WEB-INF/cas-servlet.xml",
            "file:src/main/webapp/WEB-INF/deployerConfigContext.xml",
    "file:src/main/webapp/WEB-INF/spring-configuration/*.xml"});
    applicationContext.setServletContext(new MockServletContext(new ResourceLoader() {
        @Override
        public Resource getResource(final String location) {
            return new FileSystemResource("src/main/webapp" + location);
        }

        @Override
        public ClassLoader getClassLoader() {
            return getClassLoader();
        }
    }));
    applicationContext.refresh();
}
WiringTests.java 文件源码 项目:cas-server-4.0.1 阅读 29 收藏 0 点赞 0 评论 0
@Before
public void setUp() {
    applicationContext = new XmlWebApplicationContext();
    applicationContext.setConfigLocations(new String[]{
            "file:src/main/webapp/WEB-INF/cas-management-servlet.xml",
            "file:src/main/webapp/WEB-INF/managementConfigContext.xml",
    "file:src/main/webapp/WEB-INF/spring-configuration/*.xml"});
    applicationContext.setServletContext(new MockServletContext(new ResourceLoader() {
        @Override
        public Resource getResource(final String location) {
            return new FileSystemResource("src/main/webapp" + location);
        }

        @Override
        public ClassLoader getClassLoader() {
            return getClassLoader();
        }
    }));
    applicationContext.refresh();
}
ServletInitializer.java 文件源码 项目:starter-kit-spring-maven 阅读 21 收藏 0 点赞 0 评论 0
@Override
public void onStartup(ServletContext container) throws ServletException {
    XmlWebApplicationContext context = new XmlWebApplicationContext();

    context.setConfigLocations(CONTEXT_CONFIG_LOCATIONS);

    DispatcherServlet dispatcherServlet = new DispatcherServlet(context);
    dispatcherServlet.setPublishContext(true);

    FilterRegistration.Dynamic sessionFilter = container.addFilter("sessionFilter", new DelegatingFilterProxy("sessionFilter"));

    sessionFilter.addMappingForUrlPatterns(null, false, "*.jsp");

    this.servlets.stream().forEach( servlet -> {
        addServlet(container, sessionFilter, servlet);
    });
}
HandlerTest.java 文件源码 项目:gwt-sl 阅读 70 收藏 0 点赞 0 评论 0
@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    ServletContext servletContext = new MockServletContext(
            new FileSystemResourceLoader());
    requestService = new MockHttpServletRequest("PUT", "/service");
    applicationContext = new XmlWebApplicationContext();
    applicationContext.setServletContext(servletContext);
    applicationContext.setConfigLocations(new String[] {
            "src/main/webapp/WEB-INF/handler-servlet.xml",
            "src/main/webapp/WEB-INF/applicationContext.xml" });
    try{
    applicationContext.refresh();
    }
    catch (Throwable e){
        e.printStackTrace();
    }
    handler = (GWTHandler) applicationContext.getBean("urlMapping", GWTHandler.class);
}
TestRPCExporter.java 文件源码 项目:gwt-sl 阅读 17 收藏 0 点赞 0 评论 0
@Override
@Before
public void setUp() throws Exception {

    requestPayload = readResource("request_add.txt");
    responsePayload = readResource("response_add.txt");
    MockServletContext servletContext = new MockServletContext(new ResourceLoaderSupport());
    MockServletConfig servletConfig = new MockServletConfig(servletContext);
    applicationContext = new XmlWebApplicationContext();
    applicationContext.setServletContext(servletContext);
    applicationContext.setServletConfig(servletConfig);
    applicationContext.setConfigLocations(new String[] { "src/main/webapp/WEB-INF/exporter-servlet.xml",
            "src/main/webapp/WEB-INF/applicationContext.xml" });
    applicationContext.refresh();
    handlerMapping = (SimpleUrlHandlerMapping) applicationContext
            .getBean("org.springframework.web.servlet.handler.SimpleUrlHandlerMapping");
}
SimpleUrlHandlerMappingTests.java 文件源码 项目:class-guard 阅读 18 收藏 0 点赞 0 评论 0
@Test
public void handlerBeanNotFound() throws Exception {
    MockServletContext sc = new MockServletContext("");
    XmlWebApplicationContext root = new XmlWebApplicationContext();
    root.setServletContext(sc);
    root.setConfigLocations(new String[] {"/org/springframework/web/servlet/handler/map1.xml"});
    root.refresh();
    XmlWebApplicationContext wac = new XmlWebApplicationContext();
    wac.setParent(root);
    wac.setServletContext(sc);
    wac.setNamespace("map2err");
    wac.setConfigLocations(new String[] {"/org/springframework/web/servlet/handler/map2err.xml"});
    try {
        wac.refresh();
        fail("Should have thrown NoSuchBeanDefinitionException");
    }
    catch (FatalBeanException ex) {
        NoSuchBeanDefinitionException nestedEx = (NoSuchBeanDefinitionException) ex.getCause();
        assertEquals("mainControlle", nestedEx.getBeanName());
    }
}


问题


面经


文章

微信
公众号

扫码关注公众号