【发布时间】:2016-12-13 22:37:29
【问题描述】:
相关文件-migrationruleserviceimpl
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import javax.inject.Named;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
@Named
public class MigrationRuleServiceImpl implements MigrationRuleService {
@Override
@Transactional(propagation=Propagation.REQUIRED)
public String migrationRuleUpload(MultipartFile file){
if (!file.isEmpty()) {
try {
byte[] bytes = file.getBytes();
BufferedOutputStream stream =
new BufferedOutputStream(new FileOutputStream(new File("lul")));
stream.write(bytes);
stream.close();
return "You successfully uploaded ";
} catch (Exception e) {
return "You failed to upload => " + e.getMessage();
}
} else {
return "You failed to upload because the file was empty.";
}
}
}
迁移规则服务
import org.springframework.web.multipart.MultipartFile;
public interface MigrationRuleService {
String migrationRuleUpload(MultipartFile file);
}
迁移规则控制器
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
@RestController
@RequestMapping(value = "/upload")
public class MigrationRuleController {
@RequestMapping(method = RequestMethod.POST)
public String migrationRuleUpload(@RequestParam("file") MultipartFile file) {
return migrationRuleUpload(file);
}
}
当我在邮递员中尝试此操作时,我收到内部服务器错误 500 - 来自 tomcat 日志的错误消息:
SEVERE: Servlet.service() for servlet [dispatcher] in context with path [] threw exception [Handler processing failed; nested exception is java.lang.StackOverflowError] with root cause
java.lang.StackOverflowError at MigrationRuleController.migrationRuleUpload(MigrationRuleController.java:17)
<the previous line repeated bazilion of times>
这可能有什么问题?
【问题讨论】:
-
忘了补充,MigrationRuleController.migrationRuleUpload(MigrationRuleController.java:17) 的错误行java.lang.StackOverflowError 重复了50次,不知道是否相关
标签: java spring file-upload controller postman