相關的文件 - migrationruleserviceimpl在春季創建上傳功能,出現異常拋出異常[Handler processing failed;嵌套的例外是java.lang.StackOverflowError的
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.";
}
}
}
migrationruleservice
import org.springframework.web.multipart.MultipartFile;
public interface MigrationRuleService {
String migrationRuleUpload(MultipartFile file);
}
migrationrulecontroller
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次,不知道其相關的 – Entman