當前位置: 首頁>>代碼示例>>Java>>正文


Java AnnotationConfigWebApplicationContext類代碼示例

本文整理匯總了Java中org.springframework.web.context.support.AnnotationConfigWebApplicationContext的典型用法代碼示例。如果您正苦於以下問題:Java AnnotationConfigWebApplicationContext類的具體用法?Java AnnotationConfigWebApplicationContext怎麽用?Java AnnotationConfigWebApplicationContext使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


AnnotationConfigWebApplicationContext類屬於org.springframework.web.context.support包,在下文中一共展示了AnnotationConfigWebApplicationContext類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onStartup

import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; //導入依賴的package包/類
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
	//register config classes
	AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
	rootContext.register(WebMvcConfig.class);
	rootContext.register(JPAConfig.class);
	rootContext.register(WebSecurityConfig.class);
	rootContext.register(ServiceConfig.class);
	//set session timeout
	servletContext.addListener(new SessionListener(maxInactiveInterval));
	//set dispatcher servlet and mapping
	ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher",
			new DispatcherServlet(rootContext));
	dispatcher.addMapping("/");
	dispatcher.setLoadOnStartup(1);
	
	//register filters
	FilterRegistration.Dynamic filterRegistration = servletContext.addFilter("endcodingFilter", new CharacterEncodingFilter());
	filterRegistration.setInitParameter("encoding", "UTF-8");
	filterRegistration.setInitParameter("forceEncoding", "true");
	//make sure encodingFilter is matched first
	filterRegistration.addMappingForUrlPatterns(null, false, "/*");
	//disable appending jsessionid to the URL
	filterRegistration = servletContext.addFilter("disableUrlSessionFilter", new DisableUrlSessionFilter());
	filterRegistration.addMappingForUrlPatterns(null, true, "/*");
}
 
開發者ID:Azanx,項目名稱:Smart-Shopping,代碼行數:27,代碼來源:WebMvcInitialiser.java

示例2: addDispatcherContext

import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; //導入依賴的package包/類
private void addDispatcherContext(ServletContext container) {
  // Create the dispatcher servlet's Spring application context
  AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext();
  dispatcherContext.register(SpringDispatcherConfig.class); 
  
	 
  // Declare  <servlet> and <servlet-mapping> for the DispatcherServlet
  ServletRegistration.Dynamic dispatcher = container.addServlet("ch08-servlet", 
  		new DispatcherServlet(dispatcherContext));
  dispatcher.addMapping("/");
  dispatcher.setLoadOnStartup(1);
  dispatcher.setAsyncSupported(true); 
  
  //FilterRegistration.Dynamic springSecurityFilterChain = container.addFilter("springSecurityFilterChain", new DelegatingFilterProxy());
   // springSecurityFilterChain.addMappingForUrlPatterns(null, false, "/*");
   // springSecurityFilterChain.setAsyncSupported(true);

}
 
開發者ID:PacktPublishing,項目名稱:Spring-5.0-Cookbook,代碼行數:19,代碼來源:SpringWebinitializer.java

示例3: addDispatcherContext

import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; //導入依賴的package包/類
private void addDispatcherContext(ServletContext container) {
	// Create the dispatcher servlet's Spring application context
	AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext();
	dispatcherContext.register(SpringDispatcherConfig.class);

	// Declare <servlet> and <servlet-mapping> for the DispatcherServlet
	ServletRegistration.Dynamic dispatcher = container.addServlet("ch03-servlet",
			new DispatcherServlet(dispatcherContext));
	dispatcher.addMapping("*.html");
	dispatcher.setLoadOnStartup(1);

	FilterRegistration.Dynamic corsFilter = container.addFilter("corsFilter", new CorsFilter());
	corsFilter.setInitParameter("cors.allowed.methods", "GET, POST, HEAD, OPTIONS, PUT, DELETE");
	corsFilter.addMappingForUrlPatterns(null, true, "/*");

	FilterRegistration.Dynamic filter = container.addFilter("hiddenmethodfilter", new HiddenHttpMethodFilter());
	filter.addMappingForServletNames(null, true, "/*");

	FilterRegistration.Dynamic multipartFilter = container.addFilter("multipartFilter", new MultipartFilter());
	multipartFilter.addMappingForUrlPatterns(null, true, "/*");

}
 
開發者ID:PacktPublishing,項目名稱:Spring-5.0-Cookbook,代碼行數:23,代碼來源:SpringWebInitializer.java

示例4: onStartup

import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; //導入依賴的package包/類
@Override
public void onStartup(ServletContext servletContext) throws ServletException {

    //On charge le contexte de l'app
    AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
    rootContext.setDisplayName("scrumtracker");
    rootContext.register(ApplicationContext.class);

    //Context loader listener
    servletContext.addListener(new ContextLoaderListener(rootContext));

    //Dispatcher servlet
    ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", new DispatcherServlet(rootContext));
    dispatcher.setLoadOnStartup(1);
    dispatcher.addMapping("/");
}
 
開發者ID:scrumtracker,項目名稱:scrumtracker2017,代碼行數:17,代碼來源:ApplicationInitializer.java

示例5: createAADAuthenticationFilter

import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; //導入依賴的package包/類
@Test
public void createAADAuthenticationFilter() throws Exception {
    System.setProperty(Constants.CLIENT_ID_PROPERTY, Constants.CLIENT_ID);
    System.setProperty(Constants.CLIENT_SECRET_PROPERTY, Constants.CLIENT_SECRET);
    System.setProperty(Constants.TARGETED_GROUPS_PROPERTY,
            Constants.TARGETED_GROUPS.toString().replace("[", "").replace("]", ""));

    try (AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext()) {
        context.register(AADAuthenticationFilterAutoConfiguration.class);
        context.refresh();

        final AADAuthenticationFilter azureADJwtTokenFilter = context.getBean(AADAuthenticationFilter.class);
        assertThat(azureADJwtTokenFilter).isNotNull();
        assertThat(azureADJwtTokenFilter).isExactlyInstanceOf(AADAuthenticationFilter.class);
    }

    System.clearProperty(Constants.CLIENT_ID_PROPERTY);
    System.clearProperty(Constants.CLIENT_SECRET_PROPERTY);
    System.clearProperty(Constants.TARGETED_GROUPS_PROPERTY);
}
 
開發者ID:Microsoft,項目名稱:azure-spring-boot,代碼行數:21,代碼來源:AADAuthenticationFilterAutoConfigurationTest.java

示例6: configServlet

import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; //導入依賴的package包/類
@Bean(name = "configServlet")
public ServletRegistrationBean configServlet() {
	DispatcherServlet dispatcherServlet = new DispatcherServlet();
	AnnotationConfigWebApplicationContext applicationContext = new AnnotationConfigWebApplicationContext();
	applicationContext.register(ConfigServletConfig.class);
	dispatcherServlet.setApplicationContext(applicationContext);
	ServletRegistrationBean registrationBean = new ServletRegistrationBean(dispatcherServlet, "/config/*");
	registrationBean.setLoadOnStartup(1);
	return registrationBean;
}
 
開發者ID:namics,項目名稱:spring-configuration-support,代碼行數:11,代碼來源:SampleApplication.java

示例7: onStartup

import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; //導入依賴的package包/類
/**
 * Configure the given {@link ServletContext} with any servlets, filters, listeners
 * context-params and attributes necessary for initializing this web application. See examples
 * {@linkplain WebApplicationInitializer above}.
 *
 * @param servletContext the {@code ServletContext} to initialize
 * @throws ServletException if any call against the given {@code ServletContext} throws a {@code ServletException}
 */
public void onStartup(ServletContext servletContext) throws ServletException {
	// Spring Context Bootstrapping
	AnnotationConfigWebApplicationContext rootAppContext = new AnnotationConfigWebApplicationContext();
	rootAppContext.register(AutoPivotConfig.class);
	servletContext.addListener(new ContextLoaderListener(rootAppContext));

	// Set the session cookie name. Must be done when there are several servers (AP,
	// Content server, ActiveMonitor) with the same URL but running on different ports.
	// Cookies ignore the port (See RFC 6265).
	CookieUtil.configure(servletContext.getSessionCookieConfig(), CookieUtil.COOKIE_NAME);

	// The main servlet/the central dispatcher
	final DispatcherServlet servlet = new DispatcherServlet(rootAppContext);
	servlet.setDispatchOptionsRequest(true);
	Dynamic dispatcher = servletContext.addServlet("springDispatcherServlet", servlet);
	dispatcher.addMapping("/*");
	dispatcher.setLoadOnStartup(1);

	// Spring Security Filter
	final FilterRegistration.Dynamic springSecurity = servletContext.addFilter(SPRING_SECURITY_FILTER_CHAIN, new DelegatingFilterProxy());
	springSecurity.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/*");

}
 
開發者ID:activeviam,項目名稱:autopivot,代碼行數:32,代碼來源:AutoPivotWebAppInitializer.java

示例8: onStartup

import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; //導入依賴的package包/類
@Override
public void onStartup(ServletContext container) {
	// Create the 'root' Spring application context
	AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
	rootContext.register(AppConfig.class);

	// Manage the lifecycle of the root application context
	container.addListener(new ContextLoaderListener(rootContext));

	// Create the dispatcher servlet's Spring application context
	AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext();

	// Register and map the dispatcher servlet
	ServletRegistration.Dynamic dispatcher = container
			.addServlet("dispatcher", new DispatcherServlet(dispatcherContext));
	dispatcher.setLoadOnStartup(1);
	dispatcher.addMapping("/");
}
 
開發者ID:auth0-blog,項目名稱:embedded-spring-5,代碼行數:19,代碼來源:AppConfig.java

示例9: onStartup

import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; //導入依賴的package包/類
@Override
public void onStartup(ServletContext servletContext)
		throws ServletException {
	AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
	ctx.register(MyMvcConfig.class);
	ctx.setServletContext(servletContext); // ②

	Dynamic servlet = servletContext.addServlet("dispatcher",new DispatcherServlet(ctx)); // 3
	servlet.addMapping("/");
	servlet.setLoadOnStartup(1);
}
 
開發者ID:longjiazuo,項目名稱:springMvc4.x-project,代碼行數:12,代碼來源:WebInitializer.java

示例10: addDispatcherServlet

import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; //導入依賴的package包/類
private ServletRegistration.Dynamic addDispatcherServlet(ServletContext servletContext, String servletName,
														   Class<?>[] servletContextConfigClasses, boolean allowBeanDefinitionOverriding, String... mappings) {
	Assert.notNull(servletName);
	Assert.notEmpty(servletContextConfigClasses);
	Assert.notEmpty(mappings);

	AnnotationConfigWebApplicationContext servletApplicationContext = new AnnotationConfigWebApplicationContext();
	servletApplicationContext.setAllowBeanDefinitionOverriding(allowBeanDefinitionOverriding);
	servletApplicationContext.register(servletContextConfigClasses);

	ServletRegistration.Dynamic dispatcherServlet = servletContext.addServlet(servletName, new DispatcherServlet(servletApplicationContext));

	dispatcherServlet.setLoadOnStartup(1);
	dispatcherServlet.addMapping(mappings);

	return dispatcherServlet;
}
 
開發者ID:profullstack,項目名稱:spring-seed,代碼行數:18,代碼來源:CommonWebInitializer.java

示例11: onStartup

import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; //導入依賴的package包/類
@Override
public void onStartup(ServletContext sc) throws ServletException {
    AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
    context.register(AppConfig.class);

    sc.addListener(new ContextLoaderListener(context));
    sc.setInitParameter("defaultHtmlEscape", "true");

    ServletRegistration.Dynamic dispatcher = sc.addServlet("dispatcherServlet", new DispatcherServlet(context));

    dispatcher.setLoadOnStartup(1);
    dispatcher.setAsyncSupported(true);
    dispatcher.addMapping("/");

    FilterRegistration.Dynamic securityFilter = sc.addFilter("springSecurityFilterChain", DelegatingFilterProxy.class);
    securityFilter.addMappingForUrlPatterns(null, false, "/*");
    securityFilter.setAsyncSupported(true);
}
 
開發者ID:ortolanph,項目名稱:hojeehdiaderua,代碼行數:19,代碼來源:DiaDeRuaWebInitializer.java

示例12: testCustomAuthenticationDoesNotAuthenticateWithBootSecurityUser

import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; //導入依賴的package包/類
@Test
public void testCustomAuthenticationDoesNotAuthenticateWithBootSecurityUser()
		throws Exception {
	this.context = new AnnotationConfigWebApplicationContext();
	this.context.setServletContext(new MockServletContext());

	this.context.register(AuthenticationManagerCustomizer.class,
			SecurityAutoConfiguration.class, ServerPropertiesAutoConfiguration.class);
	this.context.refresh();

	SecurityProperties security = this.context.getBean(SecurityProperties.class);
	AuthenticationManager manager = this.context.getBean(AuthenticationManager.class);

	UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(
			security.getUser().getName(), security.getUser().getPassword());
	try {
		manager.authenticate(token);
		fail("Expected Exception");
	}
	catch (AuthenticationException success) {
		// Expected
	}

	token = new UsernamePasswordAuthenticationToken("foo", "bar");
	assertThat(manager.authenticate(token)).isNotNull();
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:27,代碼來源:SecurityAutoConfigurationTests.java

示例13: onStartup

import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; //導入依賴的package包/類
@Override
public void onStartup(ServletContext container) throws ServletException {
	AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
	ctx.register(SpringConfig.class);
	ctx.setServletContext(container);
	
	ServletRegistration.Dynamic servlet = container.addServlet("dispatcher", new DispatcherServlet(ctx));
	
	servlet.setLoadOnStartup(1);
	servlet.addMapping("/");
	
	//編碼設置
	FilterRegistration.Dynamic fr = container.addFilter("encodingFilter", new CharacterEncodingFilter());
	fr.setInitParameter("encoding", "UTF-8");
	fr.setInitParameter("forceEncoding", "true");
}
 
開發者ID:icecity96,項目名稱:maven-mybatis-spring-example,代碼行數:17,代碼來源:AppInitializer.java

示例14: testDefaultRepositoryConfiguration

import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; //導入依賴的package包/類
@Test
public void testDefaultRepositoryConfiguration() throws Exception {
	this.context = new AnnotationConfigWebApplicationContext();
	this.context.setServletContext(new MockServletContext());
	this.context.register(TestConfiguration.class,
			EmbeddedDataSourceConfiguration.class,
			HibernateJpaAutoConfiguration.class,
			JpaRepositoriesAutoConfiguration.class,
			SpringDataWebAutoConfiguration.class,
			PropertyPlaceholderAutoConfiguration.class);
	this.context.refresh();
	assertThat(this.context.getBean(CityRepository.class)).isNotNull();
	assertThat(this.context.getBean(PageableHandlerMethodArgumentResolver.class))
			.isNotNull();
	assertThat(this.context.getBean(FormattingConversionService.class)
			.canConvert(Long.class, City.class)).isTrue();
}
 
開發者ID:philwebb,項目名稱:spring-boot-concourse,代碼行數:18,代碼來源:JpaWebAutoConfigurationTests.java

示例15: springHibernateConfiguration

import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; //導入依賴的package包/類
@Override
default SpringHibernateInitializer springHibernateConfiguration() {
    return new SpringHibernateInitializer() {
        @Override
        protected AnnotationConfigWebApplicationContext newApplicationContext() {
            AnnotationConfigWebApplicationContext context = super.newApplicationContext();
            context.scan(SingleAppInitializer.this.springPackagesToScan());
            return context;
        }

        @Override
        protected Class<? extends SingularDefaultPersistenceConfiguration> persistenceConfiguration() {
            return SingleAppInitializer.this.persistenceConfiguration();
        }

        @Override
        protected Class<? extends SingularDefaultBeanFactory> beanFactory() {
            return SingleAppInitializer.this.beanFactory();
        }
    };
}
 
開發者ID:opensingular,項目名稱:singular-server,代碼行數:22,代碼來源:SingleAppInitializer.java


注:本文中的org.springframework.web.context.support.AnnotationConfigWebApplicationContext類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。