An example of how to create a custom annotation to load a Java resource into a String.
Resource file located at:
/src/main/resources/query.sql
To load the query.sql into a String, apply the annotation as follows:
@Service
public class ExampleService {
@StringResourceLoader("classpath:query.sql")
public String sqlQuery;
...
}
Install Java 8, then build and run with gradle:
./gradlew clean bootRun
The webserver calls ExampleService and shows the contents of the string that was loaded from the file resource:
http://localhost:8080