How can I load a Spring resource contents and use it to set a bean property or pass it as an argument constructor?
The resource contains free text.
daoway answer was very helpful, and following Adrian remark I am adding a configuration snippet similar to daoway's code
From your component
@Autowired
private Resource contents;
@PostConstruct
public void load(){
try {
final InputStream inputStream = contents.getInputStream();
//use the stream
BufferedReader br = new BufferedReader(new InputStreamReader(inputStream ,1024);
StringBuilder stringBuilder = new StringBuilder();
String line;
while ((line = br.readLine()) != null) {
stringBuilder.append(line).append('\n');
}
br.close();
}catch (IOException e) {
LOGGER.error(message);
}
}