本文整理汇总了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, "/*");
}
示例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);
}
示例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, "/*");
}
示例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("/");
}
示例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;
}
示例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, "/*");
}
示例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("/");
}
示例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);
}
示例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;
}
示例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);
}
示例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");
}
示例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();
}
示例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();
}
};
}