Grails3 添加数据库可移植插件
步骤1、修改build.gradle文件2、修改application.yml文件3、运行Grails命令
OK,数据库移植插件插件引入成功!
步骤
从Grails2.5.1变换到Grails3.3.9之后发现之前自带的dbm命令找不到了; 经过查找发现是缺少了migration插件; 经过反复尝试成功添加,整理过程如下:
1、修改build.gradle文件
buildscript {
repositories {
mavenLocal()
maven { url "https://repo.grails.org/grails/core" }
}
dependencies {
classpath "org.grails:grails-gradle-plugin:$grailsVersion"
classpath "org.grails.plugins:hibernate5:${gormVersion - ".RELEASE"}"
classpath "com.bertramlabs.plugins:asset-pipeline-gradle:2.15.1"
// 添加依赖
classpath 'org.grails.plugins:database-migration:3.0.4'*
}
}
version "0.1"
group "grails3demo04"
apply plugin: "eclipse"
apply plugin: "idea"
apply plugin: "war"
apply plugin: "org.grails.grails-web"
apply plugin: "asset-pipeline"
apply plugin: "org.grails.grails-gsp"
repositories {
mavenLocal()
maven { url "https://dl.bintray.com/animator013/plugins/" }
}
// 添加依赖
sourceSets {
main {
resources {
srcDir 'grails-app/migrations'
}
}
}
dependencies {
// grails3自带插件
compile "org.springframework.boot:spring-boot-starter-logging"
compile "org.springframework.boot:spring-boot-autoconfigure"
compile "org.grails:grails-core"
compile "org.springframework.boot:spring-boot-starter-actuator"
compile "org.springframework.boot:spring-boot-starter-tomcat"
compile "org.grails:grails-web-boot"
compile "org.grails:grails-logging"
compile "org.grails:grails-plugin-rest"
compile "org.grails:grails-plugin-databinding"
compile "org.grails:grails-plugin-i18n"
compile "org.grails:grails-plugin-services"
compile "org.grails:grails-plugin-url-mappings"
compile "org.grails:grails-plugin-interceptors"
compile "org.grails.plugins:cache"
compile "org.grails.plugins:async"
compile "org.grails.plugins:scaffolding"
compile "org.grails.plugins:events"
compile "org.grails.plugins:hibernate5"
compile "org.hibernate:hibernate-core:5.1.16.Final"
compile "org.grails.plugins:gsp"
console "org.grails:grails-console"
profile "org.grails.profiles:web"
runtime "org.glassfish.web:el-impl:2.1.2-b03"
runtime "com.h2database:h2"
runtime "org.apache.tomcat:tomcat-jdbc"
runtime "com.bertramlabs.plugins:asset-pipeline-grails:2.15.1"
testCompile "org.grails:grails-gorm-testing-support"
testCompile "org.grails.plugins:geb"
testCompile "org.grails:grails-web-testing-support"
testRuntime "org.seleniumhq.selenium:selenium-htmlunit-driver:2.47.1"
testRuntime "net.sourceforge.htmlunit:htmlunit:2.18"
// 数据库连接
runtime 'mysql:mysql-connector-java:5.1.22'
// 数据据库移植
compile 'org.liquibase:liquibase-core:3.5.5'
compile 'org.grails.plugins:database-migration:3.0.4'
}
bootRun {
jvmArgs('-Dspring.output.ansi.enabled=always')
addResources = true
String springProfilesActive = 'spring.profiles.active'
systemProperty springProfilesActive, System.getProperty(springProfilesActive)
}
assets {
minifyJs = true
minifyCss = true
}
2、修改application.yml文件
---
grails:
profile: web
codegen:
defaultPackage: grails3demo04
gorm:
reactor:
# Whether to translate GORM events into Reactor events
# Disabled by default for performance reasons
events: false
# 添加配置
plugin:
databasemigration:
updateOnStartFileNames: 'changelog.xml'
# updateOnStart: true
info:
app:
name: '@info.app.name@'
version: '@info.app.version@'
grailsVersion: '@info.app.grailsVersion@'
spring:
main:
banner-mode: "off"
groovy:
template:
check-template-location: false
# Spring Actuator Endpoints are Disabled by Default
endpoints:
enabled: false
jmx:
enabled: true
security:
shiro:
authc:
required: false
filter:
config: |
[filters]
# Standard authentication that redirects to a login form
authcForm = org.apache.shiro.web.filter.authc.FormAuthenticationFilter
authcForm.loginUrl = /auth/login
# HTTP Basic authentication
authcBasic = org.apache.shiro.web.filter.authc.BasicHttpAuthenticationFilter
authcBasic.applicationName = Shiro Plugin Test
[urls]
/basic/** = authcBasic
/form/** = authcForm
---
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
endpoints:
jmx:
unique-names: true
---
hibernate:
cache:
queries: false
use_second_level_cache: false
use_query_cache: false
dataSource:
pooled: true
jmxExport: true
driverClassName: com.mysql.jdbc.Driver
username: root
password: root
environments:
development:
dataSource:
dbCreate: none
# dbCreate: create-drop
url: jdbc:mysql://localhost:3306/data_test
logSql: false
formatSql: true
# dbCreate: create-drop
# url: jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
test:
dataSource:
# dbCreate: update
url: jdbc:mysql://localhost:3306/data_test
production:
dataSource:
dbCreate: none
url: jdbc:mysql://localhost:3306/data_test
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
3、运行Grails命令
dbm-create-changelog changelog.groovy
OK,数据库移植插件插件引入成功!