Spring MVC Get file under WEB-INF without a request

后端 未结 7 846
暗喜
暗喜 2020-12-24 07:08

I am trying to get hold of a file ( or a directory ) under /WEB-INF/.../

outside of a request. I need it in a bean loaded at server startup.

A

7条回答
  •  独厮守ぢ
    2020-12-24 07:24

    You can use classpath resource if the file is located in the WEB_INF\classes directory. Which is where any files in your src/main/resources directory will be copied to using a normal maven build ...

    import org.springframework.core.io.Resource
    ...
    final Resource yourfile = new ClassPathResource( "myfile.txt");
    

提交回复
热议问题