gpt4 book ai didi

grails - grails应用程序大战指向两个不同的数据源(oracle和SQL)

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

我在grails2.2.0中有我的应用程序。我想使用以下设置来部署在Apache tomcat7上部署的应用程序大战:

第一个将数据源提供给Oracle的WAR

第二个WAR,数据源为SQL。

虽然我可以通过在app-config.properties文件中进行设置来实现此目的,但当我运行run-app时,却遇到了指向SQL的WAR的以下错误。

造成原因

BeanCreationException: Error creating bean with name 'sessionFactory':
Cannot resolve reference to bean 'lobHandlerDetector' while setting bean proper
ty 'obHandler';

nested exception is org.springframework.beans.factory.BeanCreat
ionException: Error creating bean with name 'lobHandlerDetector': Invocation of
init method failed;

nested exception is org.springframework.jdbc.support.MetaDat
aAccessException: Error while extracting DatabaseMetaData;

nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class 'com.mi
crosoft.sqlserver.jdbc.SQLServerDriver

请协助解决此问题。

最佳答案

我将为不同的环境配置数据源。我了解您希望应用程序实例一次只能访问一个数据库。因此,在一场 war 中,该应用程序将连接SQL Server,而在另一场 war 中,该应用程序将连接至Oracle。如果是正确的理解,我将在DataSource.groovy文件中执行以下操作:

environments {
sqlserver {
dataSource {
dbCreate = "none"
url = "jdbc:mysql://localhost:3306/mydb"
driverClassName = "com.mysql.jdbc.Driver"
dialect = "org.hibernate.dialect.MySQL5InnoDBDialect"
username = "dbowner"
password = "xxxxx"
logSql = false
pooled = true
properties {
maxActive = 30 // -1 para sem limite
minIdle = 1
minEvictableIdleTimeMillis=1800000
timeBetweenEvictionRunsMillis=1800000
numTestsPerEvictionRun=3
testOnBorrow=true
testWhileIdle=true
testOnReturn=true
validationQuery="SELECT 1"
}
}
}
oracle {
dataSource {
dbCreate = "none"
url = "jdbc:mysql://localhost:3306/myotherdb"
driverClassName = "com.mysql.jdbc.Driver"
dialect = "org.hibernate.dialect.MySQL5InnoDBDialect"
username = "dbowner"
password = "xyz"
logSql = false
pooled = true
properties {
maxActive = 30 // -1 para sem limite
minIdle = 1
minEvictableIdleTimeMillis=1800000
timeBetweenEvictionRunsMillis=1800000
numTestsPerEvictionRun=3
testOnBorrow=true
testWhileIdle=true
testOnReturn=true
validationQuery="SELECT 1"
}
}
}
}

现在,当您想要生成war文件时,只需运行以下命令:
grails -Dgrails.env=oracle war

要么
grails -Dgrails.env=sqlserver war

只要确保在BuildConfig.groovy文件中包括驱动程序依赖项(oracle和sql server)即可:
dependencies {
runtime 'your:sqlserver:dependency','your:oracle:dependency'
}

关于grails - grails应用程序大战指向两个不同的数据源(oracle和SQL),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18014442/

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