Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/324.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
java.io.FileNotFoundException(系统找不到指定的文件)_Java_Spring_Rest_Multipartform Data - Fatal编程技术网

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

java.io.FileNotFoundException(系统找不到指定的文件),java,spring,rest,multipartform-data,Java,Spring,Rest,Multipartform Data,我花了一整天的时间试图找出如何解决java.io.FileNotFoundException(系统找不到指定的文件)这个异常,但找不到。我用rest测试代码 My controller @RequestMapping(value = "aboutMe/image", method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType

我花了一整天的时间试图找出如何解决
java.io.FileNotFoundException(系统找不到指定的文件)
这个异常,但找不到。我用rest测试代码

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
我像这样在rest中测试它

任何帮助都将不胜感激

这里是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]

Save is Crud函数

当您询问异常时,始终发布异常的完整堆栈跟踪。当您将多部分位置配置为根应用程序的部署路径之外时,会发生什么情况?为什么不发布完整的堆栈跟踪?我试着发布,但是堆栈给出了一个错误,说这个问题有很多代码。如果你的意思是当我在'WEB-INF'下设置位置时,它给出了相同的错误否,我的意思是在webapps目录外。甚至从tomcat那里。类似于c:\tmp.Yes,我首先使用tomcat,但有五个例外。然后我搜索了google,发现如果我在
WEB-INF
下设置,不会给我错误。但结果是一样的。
public void saveAboutMe(Author author) {
        authorRepository.save(author);
    }