Spring MVC : read file from src/main/resources

前端 未结 5 1605
梦谈多话
梦谈多话 2020-12-03 06:30

I have a maven Spring project, there is xml file inside src/main/resources/xyz.xml. How can I read it inside spring MVC controller.

I am us

5条回答
  •  甜味超标
    2020-12-03 07:12

    You can add a field with annotation @Value to your bean:

    @Value("classpath:xyz.xml")
    private Resource resource;
    

    And then simply:

    resource.getInputStream();
    

提交回复
热议问题