我在grails2.2.0中有我的应用程序。我想使用以下设置部署在apache tomcat7上部署的应用程序war:
使用Oracle数据源的第一个WAR
带有SQL数据源的第二个WAR。
虽然我在大多数情况下这样做,但是在app-config.properties文件中设置它,当我运行app时,我得到以下指向SQL的错误。
由
引起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
请协助解决此问题。
答案 0 :(得分:1)
我会为不同的环境配置DataSource。我知道您希望应用程序实例一次只能访问一个数据库。所以在一场战争中,应用程序将连接到SQL Server,而在另一个实例中,应用程序将连接到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'
}