gpt4 book ai didi

groovy.sql.Sql Springboot 命令行

转载 作者:行者123 更新时间:2023-12-01 15:27:12 24 4
gpt4 key购买 nike

我正在尝试创建一个小型 Springboot 应用程序,它使用 groovy.sql.Sql 类连接到 Oracle 数据库(Oracle jar 已经被抓取并且位于 spring boot 类路径中)。这是一个非常简单的概念验证/测试示例。

import groovy.sql.Sql

@RestController
class ThisWillActuallyRun {

@RequestMapping("/")
String home() {
oracleSql = Sql.newInstance(jdbc:oracle:thin:@oracle-db:1521:db-name,
"oracle-user",
"oracle-pass",
"oracle.jdbc.driver.OracleDriver")

row = oracleSql.firstRow("select foo from blah")
return "ok"
}
}

当使用命令运行应用程序时:

spring run test_for_so.groovy

产生以下错误:

startup failed:
file:test_for_so.groovy: 1: unable to resolve class groovy.sql.Sql @ line 1, column 1.
import groovy.sql.Sql

最佳答案

您将哪些 groovy jar 作为依赖项包括在内? groovy jar 仅包括基本语言支持。将其更改为 groovy-all 以获得完整的语言和库包。例如,在 gradle 中,使用:

dependencies {
compile "org.codehaus.groovy:groovy-all"
...
}

在 maven 中,它看起来像这样:

<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
</dependency>
</dependencies>

如果您不需要所有内容,也可以在 groovy 包之上添加 groovy-sql

关于groovy.sql.Sql Springboot 命令行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35843036/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com