Externalized Query Example
This project employs Spring Boot and Spring Data JPA to demonstrate how to successfully read and execute a SQL statement by key from a properties file.
Prerequisites
- Java JDK 1.8u192 or better
- Gradle 4.10.3
How to compile and run unit tests
gradle test
How to publish artifact to local Maven repository
The build.gradle
file includes the maven-publish plugin which allows you to execute
gradle publishToMavenLocal
This will publish the artifact and a POM file to your .m2/repository
directory in a {groupId}/{artifactId}/{version}
sub-directory.
Details
We annotate CourseQueries
with ConfigurationProperties to encapsulate a namespace of sql.course
queries found in application.yml
We define CourseRepository
and have it extend the CrudRepository interface. We also define an additional query method using conventions.
We implement CourseService
to demonstrate how to employ a JdbcTemplate to execute a query
Finally we author a unit test for the aformentioned service. (Spring Boot Test is helpful).
An in-memory database is initialized on startup.
Credits
- Sayem Ahmed for AttributeConverter used to convert LocalDateTime