如何配置 Spring Boot 允许 Wicket 的文件上传?

How to configure Spring Boot that it permits Wicket's file upload?

我在 Web 应用程序中使用 Spring Boot 和 Apache Wicket。我必须添加文件上传。

在下面的代码中,Wicket 的 Form 组件的 onSubmit 方法被触发,但 "uploads" 为空。

@Override
            protected void onSubmit()
            {
                final List<FileUpload> uploads = fileUploadField.getFileUploads();

                if (uploads != null)
                {
                    for (FileUpload upload : uploads)
                    {
                        // Create a new file
                        File newFile = new File(getUploadFolder(), upload.getClientFileName());

                        // Check new file, delete if it already existed
                        checkFileExists(newFile);
                        try
                        {
                            // Save to new file
                            newFile.createNewFile();
                            upload.writeTo(newFile);

//                          UploadPage.this.info("saved file: " + upload.getClientFileName());
                        }
                        catch (Exception e)
                        {
                            throw new IllegalStateException("Unable to write file", e);
                        }
                    }
                }
            }

Spring的配置方法

@Override
    protected void configure(HttpSecurity http) throws Exception {
        http
            .csrf().disable()
            .authorizeRequests().antMatchers("/**").permitAll()
            .and()
            .logout()
            .permitAll();
        http.headers().frameOptions().disable();

    }

我创建了一个包含 Wicket 但不包含 Wicket 的单独应用程序 Spring 并且相同的上传代码可以正常工作。

我试过了,没用。

public class SecurityApplicationInitializer extends AbstractSecurityWebApplicationInitializer {

         @Override
         protected void beforeSpringSecurityFilterChain(ServletContext servletContext) {
          insertFilters(servletContext, new MultipartFilter()); 
         }
    } 

    @Bean(name = "filterMultipartResolver")
     public CommonsMultipartResolver getMultipartResolver() {
          CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver();
          return multipartResolver;
     }

并且当我通过 javascript 向 Form 组件的操作 url 添加以下建议时,Wicket 的 "onSubmit" 方法甚至没有被触发

Spring MVC - upload file is blocked by spring security

编辑: 当我在网络上观看时,我看到 Spring returns 302 到 Wicket 的 POST 上传请求。

将此添加到 application.properties 文件解决了问题。

spring.servlet.multipart.enabled=false