@Bean public MultipartResolver multipartResolver() { return new StandardServletMultipartResolver() { @Override public boolean isMultipart(HttpServletRequest request) { String method = request.getMethod().toLowerCase(); // By default, only POST is allowed. Since this is an 'update' // we should accept PUT. if (!Arrays.asList("put", "post").contains(method)) { return false; } String contentType = request.getContentType(); return (contentType != null && contentType.toLowerCase().startsWith("multipart/")); } }; }
@Test public void containerWithNothing() throws Exception { this.context = new AnnotationConfigEmbeddedWebApplicationContext( ContainerWithNothing.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); }
@Test public void containerWithNoMultipartJettyConfiguration() { this.context = new AnnotationConfigEmbeddedWebApplicationContext( ContainerWithNoMultipartJetty.class, BaseConfiguration.class); DispatcherServlet servlet = this.context.getBean(DispatcherServlet.class); assertThat(servlet.getMultipartResolver()).isNotNull(); assertThat(this.context.getBeansOfType(StandardServletMultipartResolver.class)) .hasSize(1); assertThat(this.context.getBeansOfType(MultipartResolver.class)).hasSize(1); verifyServletWorks(); }
@Test public void containerWithNoMultipartUndertowConfiguration() { this.context = new AnnotationConfigEmbeddedWebApplicationContext( ContainerWithNoMultipartUndertow.class, BaseConfiguration.class); DispatcherServlet servlet = this.context.getBean(DispatcherServlet.class); verifyServletWorks(); assertThat(servlet.getMultipartResolver()).isNotNull(); assertThat(this.context.getBeansOfType(StandardServletMultipartResolver.class)) .hasSize(1); assertThat(this.context.getBeansOfType(MultipartResolver.class)).hasSize(1); }
@Test public void containerWithNoMultipartTomcatConfiguration() { this.context = new AnnotationConfigEmbeddedWebApplicationContext( ContainerWithNoMultipartTomcat.class, BaseConfiguration.class); DispatcherServlet servlet = this.context.getBean(DispatcherServlet.class); assertThat(servlet.getMultipartResolver()).isNull(); assertThat(this.context.getBeansOfType(StandardServletMultipartResolver.class)) .hasSize(1); assertThat(this.context.getBeansOfType(MultipartResolver.class)).hasSize(1); verifyServletWorks(); }
@Test public void containerWithAutomatedMultipartJettyConfiguration() { this.context = new AnnotationConfigEmbeddedWebApplicationContext( ContainerWithEverythingJetty.class, BaseConfiguration.class); this.context.getBean(MultipartConfigElement.class); assertThat(this.context.getBean(StandardServletMultipartResolver.class)).isSameAs( this.context.getBean(DispatcherServlet.class).getMultipartResolver()); verifyServletWorks(); }
@Test public void containerWithAutomatedMultipartTomcatConfiguration() throws Exception { this.context = new AnnotationConfigEmbeddedWebApplicationContext( ContainerWithEverythingTomcat.class, BaseConfiguration.class); new RestTemplate().getForObject("http://localhost:" + this.context.getEmbeddedServletContainer().getPort() + "/", String.class); this.context.getBean(MultipartConfigElement.class); assertThat(this.context.getBean(StandardServletMultipartResolver.class)).isSameAs( this.context.getBean(DispatcherServlet.class).getMultipartResolver()); verifyServletWorks(); }
@Test public void containerWithAutomatedMultipartUndertowConfiguration() { this.context = new AnnotationConfigEmbeddedWebApplicationContext( ContainerWithEverythingUndertow.class, BaseConfiguration.class); this.context.getBean(MultipartConfigElement.class); verifyServletWorks(); assertThat(this.context.getBean(StandardServletMultipartResolver.class)).isSameAs( this.context.getBean(DispatcherServlet.class).getMultipartResolver()); }
@Test public void containerWithCustomMultipartResolver() throws Exception { this.context = new AnnotationConfigEmbeddedWebApplicationContext( ContainerWithCustomMultipartResolver.class, BaseConfiguration.class); MultipartResolver multipartResolver = this.context .getBean(MultipartResolver.class); assertThat(multipartResolver) .isNotInstanceOf(StandardServletMultipartResolver.class); }
@Test public void containerWithNothing() throws Exception { this.context = new AnnotationConfigEmbeddedWebApplicationContext( ContainerWithNothing.class, BaseConfiguration.class); DispatcherServlet servlet = this.context.getBean(DispatcherServlet.class); verify404(); assertNotNull(servlet.getMultipartResolver()); assertThat(this.context.getBeansOfType(StandardServletMultipartResolver.class) .size(), equalTo(1)); assertThat(this.context.getBeansOfType(MultipartResolver.class).size(), equalTo(1)); }
@Test public void containerWithNoMultipartJettyConfiguration() { this.context = new AnnotationConfigEmbeddedWebApplicationContext( ContainerWithNoMultipartJetty.class, BaseConfiguration.class); DispatcherServlet servlet = this.context.getBean(DispatcherServlet.class); assertNotNull(servlet.getMultipartResolver()); assertThat(this.context.getBeansOfType(StandardServletMultipartResolver.class) .size(), equalTo(1)); assertThat(this.context.getBeansOfType(MultipartResolver.class).size(), equalTo(1)); verifyServletWorks(); }
@Test public void containerWithNoMultipartUndertowConfiguration() { this.context = new AnnotationConfigEmbeddedWebApplicationContext( ContainerWithNoMultipartUndertow.class, BaseConfiguration.class); DispatcherServlet servlet = this.context.getBean(DispatcherServlet.class); verifyServletWorks(); assertNotNull(servlet.getMultipartResolver()); assertThat(this.context.getBeansOfType(StandardServletMultipartResolver.class) .size(), equalTo(1)); assertThat(this.context.getBeansOfType(MultipartResolver.class).size(), equalTo(1)); }
@Test public void containerWithNoMultipartTomcatConfiguration() { this.context = new AnnotationConfigEmbeddedWebApplicationContext( ContainerWithNoMultipartTomcat.class, BaseConfiguration.class); DispatcherServlet servlet = this.context.getBean(DispatcherServlet.class); assertNull(servlet.getMultipartResolver()); assertThat(this.context.getBeansOfType(StandardServletMultipartResolver.class) .size(), equalTo(1)); assertThat(this.context.getBeansOfType(MultipartResolver.class).size(), equalTo(1)); verifyServletWorks(); }
@Test public void containerWithAutomatedMultipartJettyConfiguration() { this.context = new AnnotationConfigEmbeddedWebApplicationContext( ContainerWithEverythingJetty.class, BaseConfiguration.class); this.context.getBean(MultipartConfigElement.class); assertSame(this.context.getBean(DispatcherServlet.class).getMultipartResolver(), this.context.getBean(StandardServletMultipartResolver.class)); verifyServletWorks(); }
@Test public void containerWithAutomatedMultipartTomcatConfiguration() throws Exception { this.context = new AnnotationConfigEmbeddedWebApplicationContext( ContainerWithEverythingTomcat.class, BaseConfiguration.class); new RestTemplate().getForObject("http://localhost:" + this.context.getEmbeddedServletContainer().getPort() + "/", String.class); this.context.getBean(MultipartConfigElement.class); assertSame(this.context.getBean(DispatcherServlet.class).getMultipartResolver(), this.context.getBean(StandardServletMultipartResolver.class)); verifyServletWorks(); }
@Test public void containerWithAutomatedMultipartUndertowConfiguration() { this.context = new AnnotationConfigEmbeddedWebApplicationContext( ContainerWithEverythingUndertow.class, BaseConfiguration.class); this.context.getBean(MultipartConfigElement.class); verifyServletWorks(); assertSame(this.context.getBean(DispatcherServlet.class).getMultipartResolver(), this.context.getBean(StandardServletMultipartResolver.class)); }
@Test public void containerWithCustomMultipartResolver() throws Exception { this.context = new AnnotationConfigEmbeddedWebApplicationContext( ContainerWithCustomMultipartResolver.class, BaseConfiguration.class); MultipartResolver multipartResolver = this.context .getBean(MultipartResolver.class); assertThat(multipartResolver, not(instanceOf(StandardServletMultipartResolver.class))); }
@Bean public MultipartResolver multipartResolver() { return new StandardServletMultipartResolver(); }
@Bean(name = "commonsMultipartResolver") public MultipartResolver multipartResolver() { return new StandardServletMultipartResolver(); }
@Bean(name = "multipartResolver") public MultipartResolver multipartResolver() { return new StandardServletMultipartResolver(); }
@Bean() public MultipartResolver multipartResolver(){ return new StandardServletMultipartResolver(); }
@Bean public MultipartResolver multipartResolver() { // Trarar requisições com arquivos em anexo return new StandardServletMultipartResolver(); }
@Bean(name = DispatcherServlet.MULTIPART_RESOLVER_BEAN_NAME) @ConditionalOnMissingBean(MultipartResolver.class) public StandardServletMultipartResolver multipartResolver() { return new StandardServletMultipartResolver(); }
@Bean public MultipartResolver multipartResolver() { StandardServletMultipartResolver resolver = new StandardServletMultipartResolver(); resolver.setResolveLazily(true); return resolver; }
@Bean MultipartResolver multipartResolver() { return new StandardServletMultipartResolver(); }
@Bean public StandardServletMultipartResolver multipartResolver() { StandardServletMultipartResolver ssmr = new StandardServletMultipartResolver(); return ssmr; }