【发布时间】:2017-02-06 21:40:13
【问题描述】:
我有一小组 grails 3.0.11 应用程序。我们有一个在应用程序之间共享的域模块。 当其中一个应用程序(app1、app2 等)启动时,它会连接到数据源并为域模块中的每个类创建一个表。套件中的所有应用程序都将尝试创建这些表。
我修改了 application.yml 以便它使用 MSSQL 实例而不是内部 h2 db,并且我将 dbCreate 设置为更新,以便架构将在应用程序关闭时保持不变。
我正在尝试拆分域,以便每个应用程序只管理其相关类的架构。即,app1 将在启动时处理classA、classB 和classC 的ddl,而app2 将处理classX、classY、classZ。
遵循this 指南,我定义了每个应用程序唯一的第二个数据源(即app1db、app2db 等),并且我已将mapping = { datasource 'appXdb'} 添加到指定相关应用程序的每个类中。
现在,当我启动应用程序时,我得到一个 sql 异常:
原因:java.sql.SQLException:驱动程序:jTDS 1.3.1 返回 null URL:jdbc:h2:mem:grailsDB;MVCC=TRUE;LOCK_TIMEOUT=10000
为什么我的应用程序在重新定义数据源以指向 mssql 实例并添加第二个也指向 mssql 的数据源后仍尝试访问 h2 db?
application.yml:
---
server:
port: 3434
contextPath: '/app1'
---
grails:
profile: web
codegen:
defaultPackage: cars.app
info:
app:
name: '@info.app.name@'
version: '@info.app.version@'
grailsVersion: '@info.app.grailsVersion@'
spring:
groovy:
template:
check-template-location: false
---
grails:
mime:
disable:
accept:
header:
userAgents:
- Gecko
- WebKit
- Presto
- Trident
types:
all: '*/*'
atom: application/atom+xml
css: text/css
csv: text/csv
form: application/x-www-form-urlencoded
html:
- text/html
- application/xhtml+xml
js: text/javascript
json:
- application/json
- text/json
multipartForm: multipart/form-data
pdf: application/pdf
rss: application/rss+xml
text: text/plain
hal:
- application/hal+json
- application/hal+xml
xml:
- text/xml
- application/xml
urlmapping:
cache:
maxsize: 1000
controllers:
defaultScope: singleton
converters:
encoding: UTF-8
views:
default:
codec: html
gsp:
encoding: UTF-8
htmlcodec: xml
codecs:
expression: html
scriptlets: html
taglib: none
staticparts: none
---
hibernate:
cache:
queries: false
use_second_level_cache: true
use_query_cache: false
region.factory_class: 'org.hibernate.cache.ehcache.EhCacheRegionFactory'
endpoints:
jmx:
unique-names: true
shutdown:
enabled: true
dataSources:
dataSource:
pooled: true
jmxExport: true
driverClassName: net.sourceforge.jtds.jdbc.Driver
username: grails
password: password
app1DataSource:
pooled: true
jmxExport: true
driverClassName: net.sourceforge.jtds.jdbc.Driver
username: grails
password: password
environments:
development:
dataSource:
dbCreate: update
url: jdbc:jtds:sqlserver://127.0.0.1;databaseName=cars_demo
appDataSource:
dbCreate: update
url: jdbc:jtds:sqlserver://1127.0.0.1;databaseName=cars_demo
dataSource:
dbCreate: update
url: jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1
production:
dataSource:
dbCreate: update
url: jdbc:h2:mem:prodDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1
properties:
jmxEnabled: true
initialSize: 5
maxActive: 50
minIdle: 5
maxIdle: 25
maxWait: 10000
maxAge: 600000
timeBetweenEvictionRunsMillis: 5000
minEvictableIdleTimeMillis: 60000
validationQuery: SELECT 1
validationQueryTimeout: 3
validationInterval: 15000
testOnBorrow: true
testWhileIdle: true
testOnReturn: false
jdbcInterceptors: ConnectionState
defaultTransactionIsolation: 2 # TRANSACTION_READ_COMMITTED
映射元素:static mapping = {datasource 'app1DataSource'}
edit1:添加了 application.yml 和映射元素。
【问题讨论】:
-
你应该显示 application.yml 文件
标签: sql-server hibernate grails jdbc h2