找不到[/ upload]

时间:2018-06-23 13:12:20

标签: spring spring-boot

我有一个用于读取Excel文件的控制器。  这是控制器

    @RestController
@MultipartConfig(location="/tmp",
        fileSizeThreshold=0,
        maxFileSize=5242880,       // 5 MB
        maxRequestSize=20971520)   // 20 MB
public class UploadController {

    @ApiOperation(value = "Upload mappings excel file", notes = "Uploads the excel file and stores on couchbase")

    @ApiResponses(value = {

            @ApiResponse(code = 200, message = "File uploaded successfully"),

            @ApiResponse(code = 500, message = "Internal server error"),

            @ApiResponse(code = 400, message = "Bad request")

    })

    @RequestMapping(value = "/upload", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE, consumes = "multipart/form-data")
        public void uploadMappingsExcel (@ApiParam(value = "file", example = "user.ods", required = true)
                                             @RequestParam(value = "file", required = false) MultipartFile multipartFile) throws IOException{
        Path  path = null;
        for(MultipartFile file : Collections.singleton(multipartFile)) {
            path = Paths.get(file.getOriginalFilename());
            Files.write(path,file.getBytes());
        }

        FileInputStream file = new FileInputStream(path.toString());
        XSSFWorkbook workbook = new XSSFWorkbook(file);

        Sheet sheet = workbook.getSheetAt(0);
        DataFormatter dataFormatter = new DataFormatter();
        Iterator<Row> rowIterator = sheet.iterator();
        while (rowIterator.hasNext()) {
            Row row = rowIterator.next();
            Iterator<Cell> cellIterator = row.cellIterator();
            while (cellIterator.hasNext()) {
                Cell cell = cellIterator.next();
                String cellValue = dataFormatter.formatCellValue(cell);
                System.out.print(cellValue + "\t");
            }
            System.out.println();

        }

        }

当我尝试通过邮递员运行它时,在路径[]的上下文中,servlet [dispatcherServlet]的错误Servlet.service()引发异常[请求处理失败;嵌套异常是java.lang.NullPointerException],其根本原因和一些日志为

找不到[/ upload]的处理程序方法  寻找路径[/ upload]的处理程序方法 查找路径/错误的处理程序方法 找不到/ error

的处理程序方法

Here is the code structure

Postman Result

The Logs

0 个答案:

没有答案