spring expression read file content

前端 未结 2 1591
傲寒
傲寒 2020-12-30 12:13

How to use spring expression to read file content and put it into a string?

I would like to do the following.

For example,

@Value(\"classpath         


        
2条回答
  •  再見小時候
    2020-12-30 12:21

    There is a similar question answered here which use Java configuration.

    @Configuration
    public class Spring {
    
        @Value("classpath:choice-test.html")
        private Resource sampleHtml;
    
        @Bean
        public String sampleHtmlData() {
            try(InputStream is = sampleHtml.getInputStream()) {
                return IOUtils.toString(is);
            }
        }
    }
    

提交回复
热议问题