How to access a resource file in src/main/resources/ folder in Spring Boot

后端 未结 3 948
南方客
南方客 2021-01-03 00:25

I\'m trying to access xsd in src/main/resources/XYZ/view folder where XYZ/view folder are created by me and folder has abc.xsd which I need for xml validation.

When

3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-03 01:09

    The @Value annotation is used to inject property values into variables, usually Strings or simple primitive values. You can find more info here.

    If you want to load a resource file, use a ResourceLoader like:

    @Autowired
    private ResourceLoader resourceLoader;
    
    ...
    
    final Resource fileResource = resourceLoader.getResource("classpath:XYZ/view/abc.xsd");
    

    Then you can access the resource with:

    fileResource.getInputStream() or fileResource.getFile()

提交回复
热议问题