Spring Boot access static resources missing scr/main/resources

前端 未结 8 510
别那么骄傲
别那么骄傲 2020-12-04 16:39

I am working on a Spring Boot application. I need to parse an XML file (countries.xml) on start. The problem is that I do not understand where to put it so that I could acce

8条回答
  •  不知归路
    2020-12-04 16:48

    While working with Spring Boot application, it is difficult to get the classpath resources using resource.getFile() when it is deployed as JAR as I faced the same issue. This scan be resolved using Stream which will find out all the resources which are placed anywhere in classpath.

    Below is the code snippet for the same -

    ClassPathResource classPathResource = new ClassPathResource("fileName");
    InputStream inputStream = classPathResource.getInputStream();
    content = IOUtils.toString(inputStream);
    

提交回复
热议问题