springboot重复使用MultipartFile
时间: 2023-11-29 10:46:56 浏览: 216
以下是两种在SpringBoot中重复使用MultipartFile的方法:
1. 在启动类中排除SpringBoot依赖,然后写一个配置文件UploadConfig,如下所示:
```java
@SpringBootApplication(exclude = {MultipartAutoConfiguration.class})
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
@Configuration
public class UploadConfig {
@Bean(name="multipartResolver")
public MultipartResolver multipartResolver(){
return new CommonsMultipartResolver();
}
}
```
2. 在SpringBoot启动类中加入以下代码:
```java
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
@Bean(name = "multipartResolver")
public CommonsMultipartResolver multipartResolver() {
CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver();
return multipartResolver;
}
}
```
阅读全文