gpt4 book ai didi

grails - Grails 4.0.3多个数据源-第二个数据源在服务中不可用

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

我已按照Grails Doc(https://docs.grails.org/4.0.3/guide/conf.html#multipleDatasources)中的说明/示例进行操作,但仍使用默认的dataSource。
我的application.yml包含:

dataSource:
pooled: true
jmxExport: true
dbCreate: validate
url: jdbc:oracle:thin:@XXX.XX.X.XXX:XXXX:TEST
username: username1
password: password1
driverClassName: oracle.jdbc.OracleDriver
dialect: org.hibernate.dialect.Oracle10gDialect
properties:
jmxEnabled: true
initialSize: 5
maxActive: 50
minIdle: 5
maxIdle: 25
maxWait: 10000
maxAge: 600000
timeBetweenEvictionRunsMillis: 5000
minEvictableIdleTimeMillis: 60000
validationQuery: SELECT 1 FROM DUAL
validationQueryTimeout: 3
validationInterval: 15000
testOnBorrow: true
testWhileIdle: true
testOnReturn: false
jdbcInterceptors: ConnectionState
defaultTransactionIsolation: 2 # TRANSACTION_READ_COMMITTED
dataSources:
identityDb:
url: jdbc:oracle:thin:@YYY.YY.YY.YYY:YYYYY:IDENT
username: username2
password: password2
我的服务定义如下:
class PictureService {
def grailsApplication
def assetResourceLocator
static dataSource = "identityDb"

def getPictures( identifications ) {
// Loop through all ids
for( i in identifications ) {
//try {
Sql sql = Sql.newInstance( dataSource )
...
它抛出此堆栈转储:
ORA-00942: table or view does not exist
. Stacktrace follows:

java.lang.reflect.InvocationTargetException: null
at org.grails.core.DefaultGrailsControllerClass$ReflectionInvoker.invoke(DefaultGrailsControllerClass.java:211)
at org.grails.core.DefaultGrailsControllerClass.invoke(DefaultGrailsControllerClass.java:188)
at org.grails.web.mapping.mvc.UrlMappingsInfoHandlerAdapter.handle(UrlMappingsInfoHandlerAdapter.groovy:90)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
at org.grails.web.servlet.mvc.GrailsWebRequestFilter.doFilterInternal(GrailsWebRequestFilter.java:77)
at org.grails.web.filters.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:67)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.sql.SQLException: ORA-00942: table or view does not exist
当我转储dataSource的连接字符串信息时,可以看到它是列出的第一个数据源,而不是identityDb数据源。我没有使用域类或GORM,而是直接编写SQL。任何帮助,将不胜感激!

最佳答案

编辑/更新
我将服务更改为以下内容,并且现在可以正常使用。我以为以前曾经尝试过,但是一定不能正确组合。
请注意,application.yml并未更改。
类PictureService {
def grails应用
def assetResourceLocator
def dataSource_identityDb

def getPictures( identifications ) {
// Loop through all ids
for( i in identifications ) {
try {
Sql sql = Sql.newInstance( dataSource_identityDb )
...
而且,这与在Grails 4.0.3中使用第二个数据源的官方文档中列出的有所不同。

关于grails - Grails 4.0.3多个数据源-第二个数据源在服务中不可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62802991/

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