Search in sources :

Example 1 with AnnotationConfigServletWebServerApplicationContext

use of org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext in project spring-boot by spring-projects.

the class MultipartAutoConfigurationTests method webServerWithNothing.

@Test
public void webServerWithNothing() throws Exception {
    this.context = new AnnotationConfigServletWebServerApplicationContext(WebServerWithNothing.class, BaseConfiguration.class);
    DispatcherServlet servlet = this.context.getBean(DispatcherServlet.class);
    verify404();
    assertThat(servlet.getMultipartResolver()).isNotNull();
    assertThat(this.context.getBeansOfType(StandardServletMultipartResolver.class)).hasSize(1);
    assertThat(this.context.getBeansOfType(MultipartResolver.class)).hasSize(1);
}
Also used : AnnotationConfigServletWebServerApplicationContext(org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext) DispatcherServlet(org.springframework.web.servlet.DispatcherServlet) Test(org.junit.Test)

Example 2 with AnnotationConfigServletWebServerApplicationContext

use of org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext in project spring-boot by spring-projects.

the class MultipartAutoConfigurationTests method webServerWithAutomatedMultipartUndertowConfiguration.

@Test
public void webServerWithAutomatedMultipartUndertowConfiguration() {
    this.context = new AnnotationConfigServletWebServerApplicationContext(WebServerWithEverythingUndertow.class, BaseConfiguration.class);
    this.context.getBean(MultipartConfigElement.class);
    verifyServletWorks();
    assertThat(this.context.getBean(StandardServletMultipartResolver.class)).isSameAs(this.context.getBean(DispatcherServlet.class).getMultipartResolver());
}
Also used : AnnotationConfigServletWebServerApplicationContext(org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext) Test(org.junit.Test)

Example 3 with AnnotationConfigServletWebServerApplicationContext

use of org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext in project spring-boot by spring-projects.

the class RemoteClientConfigurationTests method configure.

private void configure(String remoteUrl, boolean setSecret, String... pairs) {
    this.context = new AnnotationConfigServletWebServerApplicationContext();
    new RestartScopeInitializer().initialize(this.context);
    this.context.register(Config.class, RemoteClientConfiguration.class);
    String remoteUrlProperty = "remoteUrl:" + remoteUrl + ":" + RemoteClientConfigurationTests.remotePort;
    EnvironmentTestUtils.addEnvironment(this.context, remoteUrlProperty);
    EnvironmentTestUtils.addEnvironment(this.context, pairs);
    if (setSecret) {
        EnvironmentTestUtils.addEnvironment(this.context, "spring.devtools.remote.secret:secret");
    }
    this.context.refresh();
}
Also used : RestartScopeInitializer(org.springframework.boot.devtools.restart.RestartScopeInitializer) AnnotationConfigServletWebServerApplicationContext(org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext)

Example 4 with AnnotationConfigServletWebServerApplicationContext

use of org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext in project spring-boot by spring-projects.

the class ServletComponentScanIntegrationTests method multipartConfigIsHonoured.

@Test
public void multipartConfigIsHonoured() {
    this.context = new AnnotationConfigServletWebServerApplicationContext();
    this.context.register(TestConfiguration.class);
    new ServerPortInfoApplicationContextInitializer().initialize(this.context);
    this.context.refresh();
    @SuppressWarnings("rawtypes") Map<String, ServletRegistrationBean> beans = this.context.getBeansOfType(ServletRegistrationBean.class);
    ServletRegistrationBean<?> servletRegistrationBean = beans.get(TestMultipartServlet.class.getName());
    assertThat(servletRegistrationBean).isNotNull();
    MultipartConfigElement multipartConfig = servletRegistrationBean.getMultipartConfig();
    assertThat(multipartConfig).isNotNull();
    assertThat(multipartConfig.getLocation()).isEqualTo("test");
    assertThat(multipartConfig.getMaxRequestSize()).isEqualTo(2048);
    assertThat(multipartConfig.getMaxFileSize()).isEqualTo(1024);
    assertThat(multipartConfig.getFileSizeThreshold()).isEqualTo(512);
}
Also used : ServerPortInfoApplicationContextInitializer(org.springframework.boot.web.context.ServerPortInfoApplicationContextInitializer) MultipartConfigElement(javax.servlet.MultipartConfigElement) TestMultipartServlet(org.springframework.boot.web.servlet.testcomponents.TestMultipartServlet) AnnotationConfigServletWebServerApplicationContext(org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext) Test(org.junit.Test)

Example 5 with AnnotationConfigServletWebServerApplicationContext

use of org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext in project spring-boot by spring-projects.

the class EndpointWebMvcAutoConfiguration method createChildManagementContext.

private void createChildManagementContext() {
    AnnotationConfigServletWebServerApplicationContext childContext = new AnnotationConfigServletWebServerApplicationContext();
    childContext.setParent(this.applicationContext);
    childContext.setNamespace("management");
    childContext.setId(this.applicationContext.getId() + ":management");
    childContext.setClassLoader(this.applicationContext.getClassLoader());
    childContext.register(EndpointWebMvcChildContextConfiguration.class, PropertyPlaceholderAutoConfiguration.class, ServletWebServerFactoryAutoConfiguration.class, DispatcherServletAutoConfiguration.class);
    registerServletWebServerFactory(childContext);
    CloseManagementContextListener.addIfPossible(this.applicationContext, childContext);
    childContext.refresh();
    managementContextResolver().setApplicationContext(childContext);
}
Also used : AnnotationConfigServletWebServerApplicationContext(org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext)

Aggregations

AnnotationConfigServletWebServerApplicationContext (org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext)52 Test (org.junit.Test)41 DispatcherServlet (org.springframework.web.servlet.DispatcherServlet)8 BaseClientDetails (org.springframework.security.oauth2.provider.client.BaseClientDetails)7 ClientDetails (org.springframework.security.oauth2.provider.ClientDetails)6 Jsr250MethodSecurityMetadataSource (org.springframework.security.access.annotation.Jsr250MethodSecurityMetadataSource)4 DelegatingMethodSecurityMetadataSource (org.springframework.security.access.method.DelegatingMethodSecurityMetadataSource)4 MethodSecurityMetadataSource (org.springframework.security.access.method.MethodSecurityMetadataSource)4 ServerPortInfoApplicationContextInitializer (org.springframework.boot.web.context.ServerPortInfoApplicationContextInitializer)3 ServletContextEvent (javax.servlet.ServletContextEvent)2 ServletContextListener (javax.servlet.ServletContextListener)2 MethodSecurityExpressionHandler (org.springframework.security.access.expression.method.MethodSecurityExpressionHandler)2 PreInvocationAuthorizationAdvice (org.springframework.security.access.prepost.PreInvocationAuthorizationAdvice)2 PrePostAnnotationSecurityMetadataSource (org.springframework.security.access.prepost.PrePostAnnotationSecurityMetadataSource)2 OAuth2ClientContext (org.springframework.security.oauth2.client.OAuth2ClientContext)2 OAuth2MethodSecurityExpressionHandler (org.springframework.security.oauth2.provider.expression.OAuth2MethodSecurityExpressionHandler)2 RestTemplate (org.springframework.web.client.RestTemplate)2 StandardServletMultipartResolver (org.springframework.web.multipart.support.StandardServletMultipartResolver)2 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1