Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BS-157] Add support for MultipartConfig #2

Closed
wants to merge 19 commits into from
Closed

[BS-157] Add support for MultipartConfig #2

wants to merge 19 commits into from

Conversation

gregturn
Copy link
Contributor

This pull request is for review purposes only. This patch is by no means complete.

To support Multipart uploads, add ability to turn on some beans and servlet support if user includes a MultipartConfigElement in the app context.

gregturn and others added 13 commits June 12, 2013 17:13
To support Multipart uploads, add ability to turn on some beans
and servlet support if user includes a MultipartConfigElement in the
app context.
Update EmbeddedWebApplicationContext to obtain ServletContextInitializer
beans after self initialization. Allows @configuration beans to be
ServletContextAware.
Polish pom.xml formatting and pull version numbers into parent pom
when possible.
Update OnBeanCondition and OnMissingBeanCondition to work better
with @configuration classes and to support an optional considerHierarchy
annotation value.

The class value for conditions can now also be inferred when used on
@bean methods.
Update EnableAutoConfigurationImportSelector to sort auto-configuration
classes based on @order and @AutoConfigureAfter annotations.
Refactor JpaComponentScanDetector to a more general use utility and
ensure that details are always stored.
Polish and fixup:
- Ordered auto-configuration
- @ConditionalOnBean default on @bean methods
- Improved separation of auto-configure classes
- Consistent naming
- Javadoc, code formatting and tests
Numerous changes to the actuator project, including:
- Specific Endpoint interface
- Spring MVC/Enpoint adapter
- Management server context changes
- Consistent auto-configuration class naming
- Auto-configuration ordering
- Javadoc, code formatting and tests
@dsyer
Copy link
Member

dsyer commented Jun 13, 2013

I'm not comforatble with the container-specific code, so I think we need to abandon that here and switch to using javax.servlet.ServletRegistration. All we need to do is add support for that into ServletRegistrationBean. Probably to reach feature parity with this patch we need to scoop up a bean of type MultipartConifgElement and register it with the "free" servlets (i.e. the ones that do not already have a ServletRegistrationBean) - that would be in EmbeddedWebApplicationContext.getServletContextInitializerBeans() if you want to revise and re-submit.

User can set spring.template.cache=false to change the behaviour
@gregturn
Copy link
Contributor Author

I'm not sure about how to use ServletRegistrationBean by itself, hence I don't know how to modify it in this context to add extra support.

@philwebb
Copy link
Member

The ServletRegistrationBean just provides simple getters/setters to configure a servlet. It is similar to the servlet element in web.xml. The magic happens in the configure method, it simply delegates to servlet 3.0 ServletRegistration.Dynamic. We would need to call setMultiPartConfig here, probably from a local property.

The EmbeddedWebApplicationContext has some additional logic that allows Servlet beans to be picked up if there are no ServletRegistrationBeans. We would need some additional logic here as well.

@gregturn
Copy link
Contributor Author

Begging your pardon, but how do I wire up a minimal embedded setup using that for test purposes? So far, I have the following code, but I don't know how to bridge that to either EmbeddedWebApplicationContext or ServletRegstirationBean. What's missing so I can test my changes?

    @Test
    public void containerWithAutomatedMultipartTomcatConfiguration() {
        this.context = new AnnotationConfigEmbeddedWebApplicationContext(
                ContainerWithEverythingTomcat.class,
                MultipartAutoConfiguration.class);
        try {
            assertNotNull(this.context.getBean(MultipartConfigElement.class));
            assertNotNull(this.context.getBean(StandardServletMultipartResolver.class));
        } finally {
            this.context.close();
        }
    }

    @Configuration
    public static class ContainerWithEverythingTomcat {
        @Bean
        MultipartConfigElement multipartConfigElement() {
            return new MultipartConfigElement("");
        }

        @Bean
        TomcatEmbeddedServletContainerFactory containerFactory() {
            return new TomcatEmbeddedServletContainerFactory();
        }
    }

@gregturn
Copy link
Contributor Author

Breakthrough! Since I updated my test code with this:

        this.context = new AnnotationConfigEmbeddedWebApplicationContext(
                ContainerWithEverythingTomcat.class,
                WebMvcAutoConfiguration.class,
                MultipartAutoConfiguration.class);

...it seems the servlet is getting created and I can see my tweaks working. Let me work on this some more, and I might have an updated patch to inspect on Monday.

Zhangshunyu pushed a commit to Zhangshunyu/spring-boot that referenced this pull request Dec 16, 2017
robin88322 added a commit to robin88322/spring-boot that referenced this pull request Nov 2, 2019
philwebb added a commit that referenced this pull request Jan 16, 2020
Support an alternative fat jar format that is more amenable to Docker
image layers.

The new format arranges files in the following structure:

	BOOT-INF/
	  layers/
	    <layer-name #1>
	      /classes
	      /lib
	    <layer-name #2>
	      /classes
	      /lib

The `BOOT-INF/layers.idx` file provides the names of the layers and the
order in which they should be added (starting with the least changed).

The `JarLauncher` class can load layered jars in both fat and exploded
forms.

Closes gh-19767

Co-authored-by: Phillip Webb <pwebb@pivotal.io>
StefanBratanov added a commit to StefanBratanov/spring-boot that referenced this pull request Jun 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants