Skip to content

Example of how to load a resource file into a String using an annotation in Spring

License

Notifications You must be signed in to change notification settings

flythebluesky/annotation-resource-loader-spring

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

annotation-resource-loader-spring

An example of how to create a custom annotation to load a Java resource into a String.

Example

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;

  ...

}

Requirements

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

About

Example of how to load a resource file into a String using an annotation in Spring

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages