java.io.FileNotFoundException(系统找不到指定的文件)

时间:2018-01-03 19:10:56

标签: java spring rest multipartform-data

我花了一整天的时间试图弄清楚如何解决java.io.FileNotFoundException (The system cannot find the file specified)此异常,但是我无法用休息

测试我的代码
My controller
@RequestMapping(value = "aboutMe/image", method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE,
                   produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ResponseBody
    public String saveAboutMe(Author author, @RequestPart("image") MultipartFile authorImage) {
        //Convert Multipart file into BLOB
        try {
            Blob image = Hibernate.getLobCreator(sessionFactory.getCurrentSession()).createBlob(authorImage.getInputStream(), authorImage.getSize());
            author.setImage(image);
        } catch (HibernateException  | IOException exception) {
            System.out.println((exception.getMessage() + " " +exception));
        }
        authorService.saveAboutMe(author);
        return "saved";
    }

我的实体

@Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "HIBERNATE_SEQUENCE")
    @SequenceGenerator(name = "HIBERNATE_SEQUENCE", sequenceName = "HIBERNATE_SEQUENCE", allocationSize = 1, initialValue = 1)
    private int id;

    @Column(name = "title")
    private String title;

    @JsonFormat(pattern = "yyyy-MM-dd  HH:mm")
    @Column(name = "dateOfAuthor")
    @Temporal(TemporalType.TIMESTAMP)
    private Date modifiedTime;

    @Column(name = "aboutMe", length = 10000)
    private String aboutMe;

    @Column(name = "image")
    @Lob
    private Blob image;

我还将多部分表单数据添加到application.properties。我在 Web-INF 下设置文件夹

spring.http.multipart.max-file-size=10MB
spring.http.multipart.max-request-size=10MB
spring.http.multipart.enabled=true
spring.http.multipart.location=C:\tomcat\apache-tomcat-6.0.48\webapps\ROOT\WEB-INF\tmp

我像这样here

进行休息测试

任何帮助将不胜感激

这是 stacktrace

java.io.FileNotFoundException: C:\tomcat\apache-tomcat-6.0.48\webapps\ROOT\WEB-INF\tmp\upload_481279d9_9087_48b2_9916_f18292ac14ba_00000000.tmp (The system cannot find the file specified)
at java.io.FileInputStream.open0(Native Method) ~[na:1.8.0_121]
at java.io.FileInputStream.open(FileInputStream.java:195) ~[na:1.8.0_121]
at java.io.FileInputStream.<init>(FileInputStream.java:138) ~[na:1.8.0_121]
at org.apache.tomcat.util.http.fileupload.disk.DiskFileItem.getInputStream(DiskFileItem.java:188) ~[tomcat-embed-core-8.5.23.jar:8.5.23]

AuthorService方法

public void saveAboutMe(Author author) {
        authorRepository.save(author);
    }

保存是Crud功能

0 个答案:

没有答案