Wie zu verwenden CommonsMultipartResolver im Frühjahr Starten

Habe ich versucht, CommonsMultipartResolver im Boot die übersetzung meiner alten Anwendung (KRIEG) zu Booten, und jetzt geht es habe den folgenden code:

@Configuration
    public class TestConfig {

        @Bean
        public FilterRegistrationBean openEntityManagerFilterRegistrationBean() {
            //Set upload filter
            final MultipartFilter multipartFilter = new MultipartFilter();
            final FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(multipartFilter);
            filterRegistrationBean.addInitParameter("multipartResolverBeanName", "commonsMultipartResolver");

            return filterRegistrationBean;
        }

        @Bean
        public CommonsMultipartResolver commonsMultipartResolver() {
            final CommonsMultipartResolver commonsMultipartResolver = new CommonsMultipartResolver();
            commonsMultipartResolver.setMaxUploadSize(-1);

            return commonsMultipartResolver;
        }
    }

Ist das der richtige Weg im Boot, die Ursache sah ich einige Eigenschaften an, die eingesetzt werden, Anwendung.Eigenschaften. Würden Sie den gleichen Zweck als die Definition einer FilterRegistrationBean?

# MULTIPART (MultipartProperties)
multipart.enabled=true
multipart.file-size-threshold=0 # Threshold after which files will be written to disk.
multipart.location= # Intermediate location of uploaded files.
multipart.max-file-size=1Mb # Max file size.
multipart.max-request-size=10Mb # Max request size.

Könnte jeder irgendwelche Muster, wie es zu benutzen? Danke.

Durch die Art und Weise, versuchte Es die Eigenschaft "multipart.enabled=true", und ich bekam:

Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'enabled' of bean class [org.springframework.boot.autoconfigure.web.MultipartProperties]: Bean property 'enabled' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
    at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:1076)
    at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:927)
    at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:95)
    at org.springframework.validation.DataBinder.applyPropertyValues(DataBinder.java:749)
    at org.springframework.validation.DataBinder.doBind(DataBinder.java:645)
    at org.springframework.boot.bind.RelaxedDataBinder.doBind(RelaxedDataBinder.java:121)
    at org.springframework.validation.DataBinder.bind(DataBinder.java:630)
    at org.springframework.boot.bind.PropertiesConfigurationFactory.doBindPropertiesToTarget(PropertiesConfigurationFactory.java:253)
    at org.springframework.boot.bind.PropertiesConfigurationFactory.bindPropertiesToTarget(PropertiesConfigurationFactory.java:227)
    at org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor.postProcessBeforeInitialization(ConfigurationPropertiesBindingPostProcessor.java:296)
    ... 73 common frames omitted
Schreibe einen Kommentar