当前位置: 首页>>代码示例>>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;未经允许,请勿转载。