How to config “CommonsMultipartResolver” in spring4 without xml to upload file

前端 未结 1 893
一向
一向 2020-12-14 16:45

I use xml config spring4 is work well.like this:



        
相关标签:
1条回答
  • 2020-12-14 17:20

    From MultipartResolver Javadoc : To define an implementation, create a bean with the id "multipartResolver" in a DispatcherServlet's application context.

    In your xml configuration, the bean has the correct id of multipartResolver, but not in your current java configuration. You should write :

    @Bean
    public CommonsMultipartResolver multipartResolver() {
        CommonsMultipartResolver resolver=new CommonsMultipartResolver();
        resolver.setDefaultEncoding("utf-8");
        return resolver;
    }
    

    or

    @Bean(name = "multipartResolver")
    public CommonsMultipartResolver createMultipartResolver() {
        CommonsMultipartResolver resolver=new CommonsMultipartResolver();
        resolver.setDefaultEncoding("utf-8");
        return resolver;
    }
    
    0 讨论(0)
提交回复
热议问题