Spring 将 Groovy 用于 JDBC 的启动应用程序
Spring Boot app that uses Groovy for JDBC
我有 spring- 公开 ReST API 的启动应用程序。我正在考虑将所有 SQL 读取卸载到 Groovy SQL。 DataSource 在 Spring 中配置。我希望 Groovy 使用此数据源。顺便说一句,会有多个 DataSource 对象(连接到不同的数据库)。
最好的方法是什么 - 我想要两全其美(DI 和 groovy 简单)。该应用程序必须在 Spring 中(出于项目原因),并将使用 WebLogic 定义的数据源部署在 WebLogic 服务器中。
我的想法是从 Spring-boot 的 ReST 控制器方法中调用如下所示的 Groovy 方法:
/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;
}
有没有更好的方法? Groovy可以直接处理Data sources(多个DD)吗?在那种情况下,我不会在 Spring 配置中初始化 DataSource。
不需要事务、JPA 等。它是纯 SQL 读取操作。
实际上 Groovy、Java、Gradle 和 Spring-boot 可以混合使用,没有任何问题。我在 Groovy class 中创建了一个新的 ReST 服务并使用了 groovy.Sql。一切正常。
只是 Gradle 构建文件需要以下配置:
sourceSets {
main {
groovy {
// override the default locations, rather than adding additional ones
srcDirs = ['src/main/groovy', 'src/main/java']
}
java {
srcDirs = [] // don't compile Java code twice
}
}
}
并且在主要 Spring 配置 class 的组件扫描中还有 groovy 包 class。
我有 spring- 公开 ReST API 的启动应用程序。我正在考虑将所有 SQL 读取卸载到 Groovy SQL。 DataSource 在 Spring 中配置。我希望 Groovy 使用此数据源。顺便说一句,会有多个 DataSource 对象(连接到不同的数据库)。
最好的方法是什么 - 我想要两全其美(DI 和 groovy 简单)。该应用程序必须在 Spring 中(出于项目原因),并将使用 WebLogic 定义的数据源部署在 WebLogic 服务器中。
我的想法是从 Spring-boot 的 ReST 控制器方法中调用如下所示的 Groovy 方法:
/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;
}
有没有更好的方法? Groovy可以直接处理Data sources(多个DD)吗?在那种情况下,我不会在 Spring 配置中初始化 DataSource。
不需要事务、JPA 等。它是纯 SQL 读取操作。
实际上 Groovy、Java、Gradle 和 Spring-boot 可以混合使用,没有任何问题。我在 Groovy class 中创建了一个新的 ReST 服务并使用了 groovy.Sql。一切正常。
只是 Gradle 构建文件需要以下配置:
sourceSets {
main {
groovy {
// override the default locations, rather than adding additional ones
srcDirs = ['src/main/groovy', 'src/main/java']
}
java {
srcDirs = [] // don't compile Java code twice
}
}
}
并且在主要 Spring 配置 class 的组件扫描中还有 groovy 包 class。