Spring Framework AnnotationConfigWebApplicationContext - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Spring Framework AnnotationConfigWebApplicationContext class.

This code example shows how to use the following methods:register, setParent
  /** 
   * Initializes Spring and Spring MVC. 
   */ 
  private ServletRegistration.Dynamic initSpring(ServletContext servletContext, AnnotationConfigWebApplicationContext rootContext) { 
    log.debug("Configuring Spring Web application context"); 
    AnnotationConfigWebApplicationContext dispatcherServletConfiguration = new AnnotationConfigWebApplicationContext(); 
    dispatcherServletConfiguration.setParent(rootContext); 
    dispatcherServletConfiguration.register(DispatcherServletConfiguration.class); 
 
    log.debug("Registering Spring MVC Servlet"); 
    ServletRegistration.Dynamic dispatcherServlet = servletContext.addServlet("dispatcher", new DispatcherServlet(dispatcherServletConfiguration)); 
    dispatcherServlet.addMapping("/service/*"); 
    dispatcherServlet.setLoadOnStartup(1); 
    dispatcherServlet.setAsyncSupported(true); 
     
    return dispatcherServlet; 
  } 
 
  @Override 
  public void contextDestroyed(ServletContextEvent sce) { 
7
CodeRank
This code example shows how to use the following methods:register, setParent
  /** 
   * Initializes Spring and Spring MVC. 
   */ 
  private ServletRegistration.Dynamic initSpring(ServletContext servletContext, AnnotationConfigWebApplicationContext rootContext) { 
    log.debug("Configuring Spring Web application context"); 
    AnnotationConfigWebApplicationContext dispatcherServletConfiguration = new AnnotationConfigWebApplicationContext(); 
    dispatcherServletConfiguration.setParent(rootContext); 
    dispatcherServletConfiguration.register(DispatcherServletConfiguration.class); 
 
    log.debug("Registering Spring MVC Servlet"); 
    ServletRegistration.Dynamic dispatcherServlet = servletContext.addServlet("dispatcher", new DispatcherServlet(dispatcherServletConfiguration)); 
    dispatcherServlet.addMapping("/service/*"); 
    dispatcherServlet.setLoadOnStartup(1); 
    dispatcherServlet.setAsyncSupported(true); 
     
    return dispatcherServlet; 
  } 
 
  /** 
   * Initializes Spring Security. 
7
CodeRank
This code example shows how to use the following methods:register, setParent
  /** 
   * Initializes Spring and Spring MVC. 
   */ 
  private ServletRegistration.Dynamic initSpring(ServletContext servletContext, AnnotationConfigWebApplicationContext rootContext) { 
    log.debug("Configuring Spring Web application context"); 
    AnnotationConfigWebApplicationContext dispatcherServletConfiguration = new AnnotationConfigWebApplicationContext(); 
    dispatcherServletConfiguration.setParent(rootContext); 
    dispatcherServletConfiguration.register(DispatcherServletConfiguration.class); 
 
    log.debug("Registering Spring MVC Servlet"); 
    ServletRegistration.Dynamic dispatcherServlet = servletContext.addServlet("dispatcher", new DispatcherServlet(dispatcherServletConfiguration)); 
    dispatcherServlet.addMapping("/service/*"); 
    dispatcherServlet.setLoadOnStartup(1); 
    dispatcherServlet.setAsyncSupported(true); 
     
    return dispatcherServlet; 
  } 
 
  /** 
   * Initializes Spring Security. 
7
CodeRank
This code example shows how to use the following methods:register, getBean, refresh
     
    private UaaTestAccounts testAccounts = UaaTestAccounts.standard(null); 
 
    @Before 
    public void setUp() throws Exception { 
        webApplicationContext = new AnnotationConfigWebApplicationContext(); 
        new YamlServletProfileInitializerContextInitializer().initializeContext(webApplicationContext, "uaa.yml"); 
        webApplicationContext.register(DefaultIntegrationTestConfig.class); 
        webApplicationContext.refresh(); 
 
        FilterChainProxy springSecurityFilterChain = webApplicationContext.getBean("springSecurityFilterChain", FilterChainProxy.class); 
 
        mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext) 
                .addFilter(springSecurityFilterChain) 
                .build(); 
 
        TestClient testClient = new TestClient(mockMvc); 
        loginToken = testClient.getClientCredentialsOAuthAccessToken("login", "loginsecret", "oauth.login"); 
    } 
 
7
CodeRank
This code example shows how to use the following methods:register, setParent
  /** 
   * Initializes Spring and Spring MVC. 
   */ 
  private ServletRegistration.Dynamic initSpring(ServletContext servletContext, AnnotationConfigWebApplicationContext rootContext) { 
    log.debug("Configuring Spring Web application context"); 
    AnnotationConfigWebApplicationContext dispatcherServletConfiguration = new AnnotationConfigWebApplicationContext(); 
    dispatcherServletConfiguration.setParent(rootContext); 
    dispatcherServletConfiguration.register(DispatcherServletConfiguration.class); 
 
    log.debug("Registering Spring MVC Servlet"); 
    ServletRegistration.Dynamic dispatcherServlet = servletContext.addServlet("dispatcher", new DispatcherServlet(dispatcherServletConfiguration)); 
    dispatcherServlet.addMapping("/service/*"); 
    dispatcherServlet.setLoadOnStartup(1); 
    dispatcherServlet.setAsyncSupported(true); 
     
    return dispatcherServlet; 
  } 
 
  /** 
   * Initializes Spring Security. 
7
CodeRank
This code example shows how to use the following methods:register, getBean, refresh, registerShutdownHook, setServletContext
    private String scimCreateToken; 
    private RandomValueStringGenerator generator = new RandomValueStringGenerator(); 
 
    @Before 
    public void setUp() throws Exception { 
        webApplicationContext = new AnnotationConfigWebApplicationContext(); 
        webApplicationContext.setServletContext(new MockServletContext()); 
        new YamlServletProfileInitializer().initialize(webApplicationContext); 
        webApplicationContext.register(DefaultIntegrationTestConfig.class); 
        webApplicationContext.refresh(); 
        webApplicationContext.registerShutdownHook(); 
 
        FilterChainProxy springSecurityFilterChain = webApplicationContext.getBean("springSecurityFilterChain", FilterChainProxy.class); 
        mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext) 
                .addFilter(springSecurityFilterChain) 
                .build(); 
 
        TestClient testClient = new TestClient(mockMvc); 
        String adminToken = testClient.getClientCredentialsOAuthAccessToken("admin", "adminsecret", 
                "clients.read clients.write clients.secret"); 
7
CodeRank
This code example shows how to use the following methods:register
	 */ 
	@Override 
	protected WebApplicationContext createRootApplicationContext() { 
		Class<?>[] configClasses = getRootConfigClasses(); 
		if (!ObjectUtils.isEmpty(configClasses)) { 
			AnnotationConfigWebApplicationContext rootAppContext = new AnnotationConfigWebApplicationContext(); 
			rootAppContext.register(configClasses); 
			return rootAppContext; 
		} 
		else { 
			return null; 
		} 
	} 
 
	/** 
	 * {@inheritDoc} 
	 * <p>This implementation creates an {@link AnnotationConfigWebApplicationContext}, 
	 * providing it the annotated classes returned by {@link #getServletConfigClasses()}. 
	 */ 
	@Override 
7
CodeRank
This code example shows how to use the following methods:register
		this.tomcatServer.setBaseDir(baseDirPath);
		this.tomcatServer.setPort(this.port);
		this.tomcatServer.getService().addConnector(connector);
		this.tomcatServer.setConnector(connector);
 
		this.serverContext = new AnnotationConfigWebApplicationContext();
		this.serverContext.register(serverConfigs);
 
		Context context = this.tomcatServer.addContext("", System.getProperty("java.io.tmpdir"));
		context.addApplicationListener(WsContextListener.class.getName());
		Tomcat.addServlet(context, "dispatcherServlet", new DispatcherServlet(this.serverContext)).setAsyncSupported(true);
		context.addServletMapping("/", "dispatcherServlet");
	} 
 
	private File createTempDir(String prefix) {
		try { 
			File tempFolder = File.createTempFile(prefix + ".", "." + this.port);
			tempFolder.delete();
			tempFolder.mkdir();
			tempFolder.deleteOnExit();
6
CodeRank
This code example shows how to use the following methods:addBeanFactoryPostProcessor, refresh, setConfigLocation, setServletContext, start
	} 
 
	private WebApplicationContext setupApplicationContext(ServletContext context) { 
		log.debug("initializing Spring application context"); //$NON-NLS-1$ 
 
		AnnotationConfigWebApplicationContext appContext = new AnnotationConfigWebApplicationContext(); 
		appContext.setServletContext(context); 
		appContext.setConfigLocation(ContextConfig.class.getName()); 
		appContext.addBeanFactoryPostProcessor(new EventBusBeanFactoryPostProcessor()); 
		appContext.refresh(); 
		appContext.start(); 
		return appContext; 
	} 
 
	private void setupServletContext(ServletContext context, WebApplicationContext appContext) { 
		log.debug("initializing servlet context"); //$NON-NLS-1$ 
 
		context.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, appContext); 
 
		context.setSessionTrackingModes(EnumSet.of(SessionTrackingMode.COOKIE)); 
7
CodeRank
This code example shows how to use the following methods:register
		//        EnumSet.of(DispatcherType.REQUEST), 
		//        false, 
		//        "/*" 
		//    ); 
 
		AnnotationConfigWebApplicationContext webCtx = new AnnotationConfigWebApplicationContext(); 
		webCtx.register(RestExporterExampleRestConfig.class); 
 
		DispatcherServlet dispatcherServlet = new DispatcherServlet(webCtx); 
		ServletRegistration.Dynamic reg = servletContext.addServlet("rest-exporter", dispatcherServlet); 
		reg.setLoadOnStartup(1); 
		reg.addMapping("/*"); 
 
	} 
 
} 
7
CodeRank
See Code Examples for Spring Framework AnnotationConfigWebApplicationContext Methods: