server: contextPath: /helloworld
可以通过 run-app -port=9090这种方式修改端口号。
2.修改flush mode
现有的模式为commit,可以通过
hibernate.flush.mode
进行修改
3.grails的配置可以分为编译配置和运行时配置,编译时配置一般是通过Gradle+build.gradle,而运行时配置一般是通过grails-app/conf/application.yml文件,当然也可以通过Groovy的ConfigSlurper语法进行配置(application.groovy及runtime.groovy),application.xml是Grails 3.0引入的,可以使用系统属性方式或命令行参数方式。
production: dataSource: url: '${JDBC_CONNECTION_STRING}'
4.在这个文件里可以配置很多核心参数
(1)grails.enable.native2ascii:默认是true,如果你不需要对i18n属性文件做native2ascii转换可以关闭
(2)grails.view.default.codec:GSP文件的默认编码方法,可以是None(默认)、html、base64,为了避免XSS攻击,可以设置为html。
(3)grails.view.gsp.encoding:GSP源文件的编码(默认是utf-8)
(4)grails.mime.file.extensions:是否使用文件后来决定mime type(默认是true)
(5)grails.mime.types:支持的mime 类型的配置表
(6)grails.serverURL:server URL的绝对连接部分
(7)grails.views.gsp.sitemesh.preprocess:决定SiteMesh是否进行预处理。
(8)grails.reload.excludes 和 grails.reload.includes:定义工程指定源码件的reload行为。
5.如果你想使用LogBack使用外部的配置文件
logging: config: /Users/me/config/logback.groovy
也可以通过系统属性业配置:
$ ./gradlew -Dlogging.config=/Users/me/config/logback.groovy bootRun
也可以使用环境变量:
$ export LOGGING_CONFIG=/Users/me/config/logback.groovy $ ./gradlew bootRun
6.application.yml和application.groovy
environments: development: dataSource: dbCreate: create-drop url: jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE test: dataSource: dbCreate: update url: jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE production: dataSource: dbCreate: update url: jdbc:h2:prodDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE properties: jmxEnabled: true initialSize: 5 ...
dataSource { pooled = false driverClassName = "org.h2.Driver" username = "sa" password = "" } environments { development { dataSource { dbCreate = "create-drop" url = "jdbc:h2:mem:devDb" } } test { dataSource { dbCreate = "update" url = "jdbc:h2:mem:testDb" } } production { dataSource { dbCreate = "update" url = "jdbc:h2:prodDb" } } }
7.DataSource
(1)driverClassName:JDBC驱动的类名
(2)username/password:建立JDBC连接使用的用户名和密码
(3)url:数据库的JDBC URL
(4)dbCreate:可选值create-drop,create,update,validate
(5)pooled:是否使用连接池(默认true)
(8)dialect:Hibernate使用的dialect(方言)
(9)readOnly:是否是只读
(10)transactional:这只用在外部数据源上
(11)persistenceInterceptor:默认datasource是自动激活持久化拦截的,其它的数据源是需要设置为true,才会激活。
(12)properties:为DataSource bean设置的额外属性。
(13)jmxExport:如果设置为false,是不会为所有的数据源注册JMX MBean。
8. 配置额外的数据源
dataSource: pooled: true jmxExport: true driverClassName: org.h2.Driver username: sa password: dataSources: lookup: dialect: org.hibernate.dialect.MysqLInnoDBDialect driverClassName: com.MysqL.jdbc.Driver username: lookup password: secret url: jdbc:MysqL://localhost/lookup dbCreate: update environments: development: dataSource: dbCreate: create-drop url: jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE test: dataSource: dbCreate: update url: jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE production: dataSource: dbCreate: update url: jdbc:h2:prodDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE properties: jmxEnabled: true initialSize: 5 ... dataSources: lookup: dialect: org.hibernate.dialect.Oracle10gDialect driverClassName: oracle.jdbc.driver.OracleDriver username: lookup password: secret url: jdbc:oracle:thin:@localhost:1521:lookup dbCreate: update
9.多个数据源间的事务
grails: transaction: chainedTransactionManagerPostProcessor: enabled: true
10.scoped controllers
grails.controllers.defaultScoper
(1)prototype(默认): 每个请求创建一个controller
(2)session:每个用户sesssion创建一个controller
(3)就是单例
grails: controllers: defaultScope: singleton
默认是128000(~128KB)
grails: controllers: upload: maxFileSize: 2000000 maxRequestSize: 2000000
maxRequestSize:multipart/form-data请求的最大大小
12.改变拦截器的order
beans: authInterceptor: order: 50
13.mime types
grails: mime: 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 RSS: application/RSS+xml text: text/plain hal: - application/hal+json - application/hal+xml xml: - text/xml - application/xml
14.HttpOnly
server: session: cookie: domain: example.org http-only: true path: / secure: true
任何client 脚本访问cookier都会被禁止。
15.html encode GSP
server: session: cookie: domain: example.org http-only: true path: / secure: true
16.endpoint
spring boot的endpoint可以允许你监控和与你的应用交互。
endpoints: enabled: true
17.HTTPS和SSL
server: port: 8443 # The port to listen on ssl: enabled: true # Activate HTTPS mode on the server port key-store: <the-location-of-your-keystore> # e.g. /etc/tomcat7/keystore/tomcat.keystore key-store-password: <your-key-store-password> # e.g. changeit key-alias: <your-key-alias> # e.g. tomcat key-password: <usually-the-same-as-your-key-store-password>