私は Grails 2.2.1 を使用しており、いくつかの SQL クエリを実行できるように、カスタム データソースをサービスに注入しています。
最初の実行時には dataSource がありますが、その後の各呼び出しでは、dataSource への参照が null になります。
class ReportService {
def dataSource_myds
Object[] reportRecords(int a) {
String query = "SELECT ..."
Object[] resultSet;
Sql sql = new Sql(dataSource_myds)
// ^ Here the NullPointerException is thrown
// But it always works at the first execution
sql.eachRow(query, [a]) {
...
resultSet += result
}
return resultSet
}
}
class ReportController {
ReportService reportService
def report = {
...
Object[] resultSet1 = reportService.reportRecords(1)
...
Object[] resultSet2 = reportService.reportRecords(2)
// ^ java.lang.NullPointerException : Must specify a non-null Connection
...
}
}
誰かがこれを以前に見たことがありますか?もしそうなら、どうすればこれを回避できますか?
ここに私の DataSource.groovy があります
environments {
development {
dataSource_myds {
url = "jdbc:oracle:thin:@..."
driverClassName = "oracle.jdbc.driver.OracleDriver"
username = "..."
password = "..."
}
}
}