I have spring-boot application that exposes ReST APIs. I am considering offloading all SQL reads to Groovy SQL. The DataSource is configured in Spring. I would like Groovy to use this DataSource. Btw, there will be multiple DataSource objects (connecting to different datbases).
What is the best approach for this - I want best of both worlds (DI and groovy simplicity). The App has to be in Spring (for project reasons) and will be deployed in WebLogic server utilizing WebLogic defined Data sources.
My idea is to call a Groovy method as shown below from the ReST controller method of Spring-boot:
/student/id
Student getStudentDetails(int id){
@Autowired
@Qualifier("someDataSource");
DataSource myDs;
Student student = GroovySqlUtil.findStudentById(id, myDs); // pass the DS to Groovy sothat GrooySQL can use the DS for executing queries.
return student;
}
Is there a better way? Can Groovy directly handle Data sources (multiple DDs)? In that case I won't initialize DataSource in Spring configuration.
There's no requirement for transactions, JPA etc. It's pure SQL read operations.