当前位置: 首页>>代码示例>>Java>>正文


Java AnnotationConfigEmbeddedWebApplicationContext类代码示例

本文整理汇总了Java中org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext的典型用法代码示例。如果您正苦于以下问题:Java AnnotationConfigEmbeddedWebApplicationContext类的具体用法?Java AnnotationConfigEmbeddedWebApplicationContext怎么用?Java AnnotationConfigEmbeddedWebApplicationContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


AnnotationConfigEmbeddedWebApplicationContext类属于org.springframework.boot.context.embedded包,在下文中一共展示了AnnotationConfigEmbeddedWebApplicationContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testJsr250SecurityAnnotationOverride

import org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext; //导入依赖的package包/类
@Test
public void testJsr250SecurityAnnotationOverride() {
	this.context = new AnnotationConfigEmbeddedWebApplicationContext();
	this.context.register(Jsr250EnabledConfiguration.class,
			MinimalSecureWebApplication.class);
	this.context.refresh();
	this.context.getBean(OAuth2MethodSecurityConfiguration.class);
	ClientDetails config = this.context.getBean(ClientDetails.class);
	DelegatingMethodSecurityMetadataSource source = this.context
			.getBean(DelegatingMethodSecurityMetadataSource.class);
	List<MethodSecurityMetadataSource> sources = source
			.getMethodSecurityMetadataSources();
	assertThat(sources.size()).isEqualTo(1);
	assertThat(sources.get(0).getClass().getName())
			.isEqualTo(Jsr250MethodSecurityMetadataSource.class.getName());
	verifyAuthentication(config, HttpStatus.OK);
}
 
开发者ID:philwebb,项目名称:spring-boot-concourse,代码行数:18,代码来源:OAuth2AutoConfigurationTests.java

示例2: agentServletWithCustomPath

import org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext; //导入依赖的package包/类
@Test
public void agentServletWithCustomPath() throws Exception {
	this.context = new AnnotationConfigEmbeddedWebApplicationContext();
	EnvironmentTestUtils.addEnvironment(this.context,
			"endpoints.jolokia.path=/foo/bar");
	this.context.register(EndpointsConfig.class, WebMvcAutoConfiguration.class,
			PropertyPlaceholderAutoConfiguration.class,
			ManagementServerPropertiesAutoConfiguration.class,
			HttpMessageConvertersAutoConfiguration.class,
			JolokiaAutoConfiguration.class);
	this.context.refresh();
	assertThat(this.context.getBeanNamesForType(JolokiaMvcEndpoint.class)).hasSize(1);
	MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context).build();
	mockMvc.perform(MockMvcRequestBuilders.get("/foo/bar"))
			.andExpect(MockMvcResultMatchers.content()
					.string(Matchers.containsString("\"request\":{\"type\"")));
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:18,代码来源:JolokiaAutoConfigurationTests.java

示例3: testEnvironmentalOverrides

import org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext; //导入依赖的package包/类
@Test
public void testEnvironmentalOverrides() {
	this.context = new AnnotationConfigEmbeddedWebApplicationContext();
	EnvironmentTestUtils.addEnvironment(this.context,
			"security.oauth2.client.clientId:myclientid",
			"security.oauth2.client.clientSecret:mysecret",
			"security.oauth2.client.autoApproveScopes:read,write",
			"security.oauth2.client.accessTokenValiditySeconds:40",
			"security.oauth2.client.refreshTokenValiditySeconds:80");
	this.context.register(AuthorizationAndResourceServerConfiguration.class,
			MinimalSecureWebApplication.class);
	this.context.refresh();
	ClientDetails config = this.context.getBean(ClientDetails.class);
	assertThat(config.getClientId()).isEqualTo("myclientid");
	assertThat(config.getClientSecret()).isEqualTo("mysecret");
	assertThat(config.isAutoApprove("read")).isTrue();
	assertThat(config.isAutoApprove("write")).isTrue();
	assertThat(config.isAutoApprove("foo")).isFalse();
	assertThat(config.getAccessTokenValiditySeconds()).isEqualTo(40);
	assertThat(config.getRefreshTokenValiditySeconds()).isEqualTo(80);
	verifyAuthentication(config);
}
 
开发者ID:philwebb,项目名称:spring-boot-concourse,代码行数:23,代码来源:OAuth2AutoConfigurationTests.java

示例4: testClassicSecurityAnnotationOverride

import org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext; //导入依赖的package包/类
@Test
public void testClassicSecurityAnnotationOverride() {
	this.context = new AnnotationConfigEmbeddedWebApplicationContext();
	this.context.register(SecuredEnabledConfiguration.class,
			MinimalSecureWebApplication.class);
	this.context.refresh();
	this.context.getBean(OAuth2MethodSecurityConfiguration.class);
	ClientDetails config = this.context.getBean(ClientDetails.class);
	DelegatingMethodSecurityMetadataSource source = this.context
			.getBean(DelegatingMethodSecurityMetadataSource.class);
	List<MethodSecurityMetadataSource> sources = source
			.getMethodSecurityMetadataSources();
	assertThat(sources.size()).isEqualTo(1);
	assertThat(sources.get(0).getClass().getName())
			.isEqualTo(SecuredAnnotationSecurityMetadataSource.class.getName());
	verifyAuthentication(config, HttpStatus.OK);
}
 
开发者ID:philwebb,项目名称:spring-boot-concourse,代码行数:18,代码来源:OAuth2AutoConfigurationTests.java

示例5: testSecurityFilterDoesNotCauseEarlyInitialization

import org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext; //导入依赖的package包/类
@Test
public void testSecurityFilterDoesNotCauseEarlyInitialization() throws Exception {
	AnnotationConfigEmbeddedWebApplicationContext context = new AnnotationConfigEmbeddedWebApplicationContext();
	try {
		EnvironmentTestUtils.addEnvironment(context, "server.port:0",
				"security.user.password:password");
		context.register(Config.class);
		context.refresh();
		int port = context.getEmbeddedServletContainer().getPort();
		new TestRestTemplate("user", "password")
				.getForEntity("http://localhost:" + port, Object.class);
		// If early initialization occurred a ConverterNotFoundException is thrown

	}
	finally {
		context.close();
	}

}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:20,代码来源:SecurityFilterAutoConfigurationEarlyInitializationTests.java

示例6: deviceDelegatingThymeleafViewResolverDisabled

import org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext; //导入依赖的package包/类
@Test(expected = NoSuchBeanDefinitionException.class)
public void deviceDelegatingThymeleafViewResolverDisabled() throws Exception {
	this.context = new AnnotationConfigEmbeddedWebApplicationContext();
	EnvironmentTestUtils.addEnvironment(this.context,
			"spring.mobile.devicedelegatingviewresolver.enabled:false");
	this.context.register(Config.class, WebMvcAutoConfiguration.class,
			ThymeleafAutoConfiguration.class,
			HttpMessageConvertersAutoConfiguration.class,
			PropertyPlaceholderAutoConfiguration.class,
			DeviceDelegatingViewResolverConfiguration.class);
	this.context.refresh();
	assertThat(this.context.getBean(InternalResourceViewResolver.class)).isNotNull();
	assertThat(this.context.getBean(ThymeleafViewResolver.class)).isNotNull();
	this.context.getBean("deviceDelegatingViewResolver",
			AbstractDeviceDelegatingViewResolver.class);
}
 
开发者ID:philwebb,项目名称:spring-boot-concourse,代码行数:17,代码来源:DeviceDelegatingViewResolverAutoConfigurationTests.java

示例7: testAuthorizationServerOverride

import org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext; //导入依赖的package包/类
@Test
public void testAuthorizationServerOverride() {
	this.context = new AnnotationConfigEmbeddedWebApplicationContext();
	EnvironmentTestUtils.addEnvironment(this.context,
			"security.oauth2.resourceId:resource-id");
	this.context.register(AuthorizationAndResourceServerConfiguration.class,
			CustomAuthorizationServer.class, MinimalSecureWebApplication.class);
	this.context.refresh();
	BaseClientDetails config = new BaseClientDetails();
	config.setClientId("client");
	config.setClientSecret("secret");
	config.setResourceIds(Arrays.asList("resource-id"));
	config.setAuthorizedGrantTypes(Arrays.asList("password"));
	config.setAuthorities(AuthorityUtils.commaSeparatedStringToAuthorityList("USER"));
	config.setScope(Arrays.asList("read"));
	assertThat(countBeans(AUTHORIZATION_SERVER_CONFIG)).isEqualTo(0);
	assertThat(countBeans(RESOURCE_SERVER_CONFIG)).isEqualTo(1);
	verifyAuthentication(config);
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:20,代码来源:OAuth2AutoConfigurationTests.java

示例8: testDefaultPrePostSecurityAnnotations

import org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext; //导入依赖的package包/类
@Test
public void testDefaultPrePostSecurityAnnotations() {
	this.context = new AnnotationConfigEmbeddedWebApplicationContext();
	this.context.register(AuthorizationAndResourceServerConfiguration.class,
			MinimalSecureWebApplication.class);
	this.context.refresh();
	this.context.getBean(OAuth2MethodSecurityConfiguration.class);
	ClientDetails config = this.context.getBean(ClientDetails.class);
	DelegatingMethodSecurityMetadataSource source = this.context
			.getBean(DelegatingMethodSecurityMetadataSource.class);
	List<MethodSecurityMetadataSource> sources = source
			.getMethodSecurityMetadataSources();
	assertThat(sources.size()).isEqualTo(1);
	assertThat(sources.get(0).getClass().getName())
			.isEqualTo(PrePostAnnotationSecurityMetadataSource.class.getName());
	verifyAuthentication(config);
}
 
开发者ID:philwebb,项目名称:spring-boot-concourse,代码行数:18,代码来源:OAuth2AutoConfigurationTests.java

示例9: deviceDelegatingThymeleafViewResolverEnabled

import org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext; //导入依赖的package包/类
@Test
public void deviceDelegatingThymeleafViewResolverEnabled() throws Exception {
	this.context = new AnnotationConfigEmbeddedWebApplicationContext();
	EnvironmentTestUtils.addEnvironment(this.context,
			"spring.mobile.devicedelegatingviewresolver.enabled:true");
	this.context.register(Config.class, WebMvcAutoConfiguration.class,
			ThymeleafAutoConfiguration.class,
			HttpMessageConvertersAutoConfiguration.class,
			PropertyPlaceholderAutoConfiguration.class,
			DeviceDelegatingViewResolverConfiguration.class);
	this.context.refresh();
	ThymeleafViewResolver thymeleafViewResolver = this.context
			.getBean(ThymeleafViewResolver.class);
	AbstractDeviceDelegatingViewResolver deviceDelegatingViewResolver = this.context
			.getBean("deviceDelegatingViewResolver",
					AbstractDeviceDelegatingViewResolver.class);
	assertThat(thymeleafViewResolver).isNotNull();
	assertThat(deviceDelegatingViewResolver).isNotNull();
	assertThat(deviceDelegatingViewResolver.getViewResolver())
			.isInstanceOf(ThymeleafViewResolver.class);
	assertThat(this.context.getBean(InternalResourceViewResolver.class)).isNotNull();
	assertThat(this.context.getBean(ThymeleafViewResolver.class)).isNotNull();
	assertThat(deviceDelegatingViewResolver.getOrder())
			.isEqualTo(thymeleafViewResolver.getOrder() - 1);
}
 
开发者ID:philwebb,项目名称:spring-boot-concourse,代码行数:26,代码来源:DeviceDelegatingViewResolverAutoConfigurationTests.java

示例10: onApplicationEvent

import org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext; //导入依赖的package包/类
@Override
public void onApplicationEvent(ApplicationEvent event) {
    if(event instanceof ContextRefreshedEvent) {
        ApplicationContext applicationContext = ((ContextRefreshedEvent) event).getApplicationContext();
        if(applicationContext instanceof AnnotationConfigEmbeddedWebApplicationContext) {
            ((AnnotationConfigEmbeddedWebApplicationContext) applicationContext).getBeanFactory().registerSingleton("simpleBeanInListener", new SimpleBeanInListener());
        }

    }
}
 
开发者ID:fangjian0423,项目名称:springboot-analysis,代码行数:11,代码来源:MyApplicationListener.java

示例11: createRootApplicationContext

import org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext; //导入依赖的package包/类
protected WebApplicationContext createRootApplicationContext(
		ServletContext servletContext) {
	SpringApplicationBuilder builder = createSpringApplicationBuilder();
	builder.main(getClass());
	ApplicationContext parent = getExistingRootWebApplicationContext(servletContext);
	if (parent != null) {
		this.logger.info("Root context already created (using as parent).");
		servletContext.setAttribute(
				WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, null);
		builder.initializers(new ParentContextApplicationContextInitializer(parent));
	}
	builder.initializers(
			new ServletContextApplicationContextInitializer(servletContext));
	builder.contextClass(AnnotationConfigEmbeddedWebApplicationContext.class);
	builder = configure(builder);
	SpringApplication application = builder.build();
	if (application.getSources().isEmpty() && AnnotationUtils
			.findAnnotation(getClass(), Configuration.class) != null) {
		application.getSources().add(getClass());
	}
	Assert.state(!application.getSources().isEmpty(),
			"No SpringApplication sources have been defined. Either override the "
					+ "configure method or add an @Configuration annotation");
	// Ensure error pages are registered
	if (this.registerErrorPageFilter) {
		application.getSources().add(ErrorPageFilter.class);
	}
	return run(application);
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:30,代码来源:SpringBootServletInitializer.java

示例12: componentsAreRegistered

import org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext; //导入依赖的package包/类
@Test
public void componentsAreRegistered() {
	this.context = new AnnotationConfigEmbeddedWebApplicationContext();
	this.context.register(TestConfiguration.class);
	new ServerPortInfoApplicationContextInitializer().initialize(this.context);
	this.context.refresh();
	String port = this.context.getEnvironment().getProperty("local.server.port");
	String response = new RestTemplate()
			.getForObject("http://localhost:" + port + "/test", String.class);
	assertThat(response).isEqualTo("alpha bravo");
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:12,代码来源:ServletComponentScanIntegrationTests.java

示例13: doTest

import org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext; //导入依赖的package包/类
private void doTest(AnnotationConfigEmbeddedWebApplicationContext context,
		String resourcePath, HttpStatus status) throws Exception {
	int port = context.getEmbeddedServletContainer().getPort();
	RestTemplate template = new RestTemplate();
	ResponseEntity<String> entity = template.getForEntity(
			new URI("http://localhost:" + port + resourcePath), String.class);
	assertThat(entity.getBody()).isEqualTo("Hello World");
	assertThat(entity.getStatusCode()).isEqualTo(status);
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:10,代码来源:ErrorPageFilterIntegrationTests.java

示例14: loadContext

import org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext; //导入依赖的package包/类
@Override
public ApplicationContext loadContext(MergedContextConfiguration config)
		throws Exception {
	AnnotationConfigEmbeddedWebApplicationContext context = new AnnotationConfigEmbeddedWebApplicationContext(
			config.getClasses());
	context.registerShutdownHook();
	return context;
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:9,代码来源:ErrorPageFilterIntegrationTests.java

示例15: defaultApplicationContextForWeb

import org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext; //导入依赖的package包/类
@Test
public void defaultApplicationContextForWeb() throws Exception {
	SpringApplication application = new SpringApplication(ExampleWebConfig.class);
	application.setWebEnvironment(true);
	this.context = application.run();
	assertThat(this.context)
			.isInstanceOf(AnnotationConfigEmbeddedWebApplicationContext.class);
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:9,代码来源:SpringApplicationTests.java


注:本文中的org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。