我正在为我的应用程序使用Spring Boot,我想将一些文件上传到我的数据库中.我用了一个教程来实现这一点,它运行正常.我的问题是我不知道如何设置要上传的最大文件大小.默认值是1MB,但这对我来说还不够.
我将这些行添加到我的application.properties:
spring.http.multipart.max-file-size = 100MB
spring.http.multipart.max-request-size = 100MB
但它没有帮助.
我的代码:
FileService.java
@Service
public class FileService {
@Autowired
FileRepository fileRepository;
public Response uploadFile(MultipartHttpServletRequest request) throws IOException {
Response response = new Response();
List fileList = new ArrayList();
Iterator<String> itr = request.getFileNames();
while (itr.hasNext()) {
String uploadedFile = itr.next();
MultipartFile file = request.getFile(uploadedFile);
String mimeType = file.getContentType();
String filename = file.getOriginalFilename();
byte[] bytes = file.getBytes();
File newFile = new File(filename, bytes, mimeType);
File savedFile = fileRepository.saveAndFlush(newFile);
savedFile.setFile(null);
fileList.add(savedFile);
}
response.setReport(fileList);
return …Run Code Online (Sandbox Code Playgroud) 我正在尝试遵循这个 spring-lemon 入门教程(https://naturalprogrammer.gitbooks.io/spring-lemon-getting-started/content/index.html),但在某个时刻我无法进一步进行。我创建了一个新的 spring 启动项目(Spring boot),并且我能够向其中添加 spring 柠檬。除了按照说明进行操作之外,我什么也没做,但是当我开始 Maven 构建时,测试失败并出现以下错误:
org.springframework.beans.factory.BeanCreationException:创建名称为“lmnDemoController”的bean时出错:自动装配依赖项注入失败;嵌套异常是 org.springframework.beans.factory.BeanCreationException:无法自动装配方法:public void com.naturalprogrammer.spring.lemon.LemonController.setLemonService(com.naturalprogrammer.spring.lemon.LemonService); 嵌套异常是 org.springframework.beans.factory.BeanCurrentlyInCreationException:创建名称为“lmnDemoService”的 bean 时出错:名称为“lmnDemoService”的 Bean 已作为循环引用的一部分注入其原始版本中的其他 bean [authenticationSuccessHandler],但已注入最终被包裹。这意味着所述其他 bean 不使用该 bean 的最终版本。这通常是过度渴望类型匹配的结果 - 例如,考虑使用“getBeanNamesOfType”并关闭“allowEagerInit”标志。
我的LmnDemoService.java是:
package com.example;
import org.springframework.stereotype.Service;
import com.naturalprogrammer.spring.lemon.LemonService;
@Service
public class LmnDemoService extends LemonService<User, Long> {
@Override
protected User newUser() {
return new User();
}
}
Run Code Online (Sandbox Code Playgroud)
它没有任何其他内容,只是教程中所说的几行内容。我缺少什么?
编辑:
LmndemoApplication.java
package com.example;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import com.naturalprogrammer.spring.lemon.LemonConfig;
@SpringBootApplication(scanBasePackageClasses = {LmndemoApplication.class, LemonConfig.class})
public class LmndemoApplication {
public static void main(String[] …Run Code Online (Sandbox Code Playgroud) spring ×2
file ×1
java ×1
max ×1
size ×1
spring-boot ×1
spring-lemon ×1
spring-mvc ×1
upload ×1