- 浏览: 2552696 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
nation:
你好,在部署Mesos+Spark的运行环境时,出现一个现象, ...
Spark(4)Deal with Mesos -
sillycat:
AMAZON Relatedhttps://www.godad ...
AMAZON API Gateway(2)Client Side SSL with NGINX -
sillycat:
sudo usermod -aG docker ec2-use ...
Docker and VirtualBox(1)Set up Shared Disk for Virtual Box -
sillycat:
Every Half an Hour30 * * * * /u ...
Build Home NAS(3)Data Redundancy -
sillycat:
3 List the Cron Job I Have>c ...
Build Home NAS(3)Data Redundancy
Grails(2)Clinic Sample and Guide Book
Find the most recent sample from here:
https://github.com/grails-samples/grails-petclinic.git
>git clone https://github.com/grails-samples/grails-petclinic.git
Import the project into my STS, install the latest grails on MAC
>sudo port install grails
Follow the document and run the sample first
>grailsw run-app
Then I can visit the sample web page from this URL http://localhost:8080/petclinic.
I can also use my STS web container to run this web project. It is also working. I will go this project in details.
1. PetClinic Application Overview
It is built on already established Java technology like Spring & Hibernate.
Object Relational Mapping(ORM) on Hibernate
View technology called Groovy Server Pages(GSP)
Spring MVC and etc
H2 is the default database used by Grails.
PetClinic Application Design
Logging
http://grails.org/doc/latest/guide/conf.html#logging
grails-app/Config.groovy
Business Layer
org.grails.samples.Speciality
org.grails.samples.PetType
org.grails.samples.Person
org.grails.samples.Vet
org.grails.samples.Owner
org.grails.samples.Pet
org.grails.samples.Visit
Logical Views & Implemented Use Cases
grails-app/views/clinic/index.gsp home
grails-app/views/clinic/vets.gsp vets and specialties
grails-app/views/owner/find.gsp
grails-app/views/owner/selection.gsp select the users from the same last name
grails-app/views/owner/show.gsp
grails-app/views/owner/add.gsp
grails-app/views/pet/add.gsp
grails-app/views/pet/addVisit.gsp
grails-app/views/common/_formField.gsp A template used to render common markup
grails-app/views/layouts/main.gsp The layout used to include common CSS and markup
Testing test the controller layer.
During reading the sample, here is for looking up http://grails.org/doc/latest/guide/index.html.
Make a sample project Dude Money Master
2. Getting Started
I successfully installed grails on my MAC and used the IDE STS.
>grails run-app
>grails test-app
>grails war
4. Configuration
4.1 Basic Configuration
grails-app/conf/BuildConfig.groovy
grails-app/conf/Config.groovy
The syntax is coming from the Grails-ConfigSlurper http://sillycat.iteye.com/blog/1567542.
The configuration has some benefits:
1. Can be merged
2. Can be written to disk
3. Convert to java properties, convert from java properties
4. the content can be structured
5. Can select the environment
def config = new ConfigSlurper("development").parse(new File('Sample.groovy').toURL())
config =newConfigSlurper("test").parse(newFile('Sample.groovy').toURL())
BuildConfig.groovy is used for compile, doc and etc.
Config.groovy is for settings that are used when the application is running.
So the Config.groovy is packaged in war, BuildConfig.groovy is not.
foo.bar.hello = "world"
It is import to have the quotes. The property values can be any valid Groovy type, strings, integers, or arbitrary objects.
Some implicit variables can not be used:
userHome home directory for the account that is running the grails
grailsHome
appName application name as it appears in application.properties
appVersion version in application.properties
BuildConfig.groovy is only available from command script via grailsSettings.config
Config.groovy is via grailsApplication in controllers
def recipient = grailsApplication.config.foo.bar.hello
And it can be easily injected into services.
class MyService{
def grailsApplication
String greeting(){
def recipient = grailsApplication.config.foo.bar.hello
…snip...
}
}
4.1.1 Built in options
Runtime Settings
grails.config.location The location of properties files can be set to other class path or userHome place.
http://grails.org/doc/latest/guide/single.html#configExternalized
grails.war.dependencies Manage the jars in war.
4.1.2 Logging
The Basics
log4j setting in Config.groovy
Logging Levels
1. off
2. fatal
3. error
4. warn
5. info
6. debug
7. trace
8. all
Loggers
class MyClass {
private static final log = LogFactory.getLog(this)
…snip…
}
The Root Logger
log4j = {
appenders {
file name: 'file', file:'/var/logs/mylog.log'
}
root{
debug 'stdout', 'file'
}
}
The root logger will log to 2 appenders. The default 'stdout' (console) apppender and file appender.
These are the default available appenders.
jdbc JDBCAppender
console ConsoleAppender
file FileAppender
rollingFile RollingFileAppender
Environment-specific configuration
// other shared config
info "grails.app.controller"
environments {
production {
// Override previous setting for 'grails.app.controller'
error "grails.app.controllers"
}
}
4.1.3 GORM
grails.gorm.failOnError=true
grails.gorm.autoFlush=true
4.2 Environments
Per Environment Configuration
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"
}
}
}Packaging and Running for Different Environments
>grails [envrionment] [command name]
references:
http://sillycat.iteye.com/blog/1567542
http://sillycat.iteye.com/blog/1074642
http://www.grails.org/tutorials?offset=0&max=10
https://github.com/grails-samples
http://grails.org/doc/latest/guide/index.html
http://grails.org/doc/latest/guide/conf.html
Find the most recent sample from here:
https://github.com/grails-samples/grails-petclinic.git
>git clone https://github.com/grails-samples/grails-petclinic.git
Import the project into my STS, install the latest grails on MAC
>sudo port install grails
Follow the document and run the sample first
>grailsw run-app
Then I can visit the sample web page from this URL http://localhost:8080/petclinic.
I can also use my STS web container to run this web project. It is also working. I will go this project in details.
1. PetClinic Application Overview
It is built on already established Java technology like Spring & Hibernate.
Object Relational Mapping(ORM) on Hibernate
View technology called Groovy Server Pages(GSP)
Spring MVC and etc
H2 is the default database used by Grails.
PetClinic Application Design
Logging
http://grails.org/doc/latest/guide/conf.html#logging
grails-app/Config.groovy
Business Layer
org.grails.samples.Speciality
org.grails.samples.PetType
org.grails.samples.Person
org.grails.samples.Vet
org.grails.samples.Owner
org.grails.samples.Pet
org.grails.samples.Visit
Logical Views & Implemented Use Cases
grails-app/views/clinic/index.gsp home
grails-app/views/clinic/vets.gsp vets and specialties
grails-app/views/owner/find.gsp
grails-app/views/owner/selection.gsp select the users from the same last name
grails-app/views/owner/show.gsp
grails-app/views/owner/add.gsp
grails-app/views/pet/add.gsp
grails-app/views/pet/addVisit.gsp
grails-app/views/common/_formField.gsp A template used to render common markup
grails-app/views/layouts/main.gsp The layout used to include common CSS and markup
Testing test the controller layer.
During reading the sample, here is for looking up http://grails.org/doc/latest/guide/index.html.
Make a sample project Dude Money Master
2. Getting Started
I successfully installed grails on my MAC and used the IDE STS.
>grails run-app
>grails test-app
>grails war
4. Configuration
4.1 Basic Configuration
grails-app/conf/BuildConfig.groovy
grails-app/conf/Config.groovy
The syntax is coming from the Grails-ConfigSlurper http://sillycat.iteye.com/blog/1567542.
The configuration has some benefits:
1. Can be merged
2. Can be written to disk
3. Convert to java properties, convert from java properties
4. the content can be structured
5. Can select the environment
def config = new ConfigSlurper("development").parse(new File('Sample.groovy').toURL())
config =newConfigSlurper("test").parse(newFile('Sample.groovy').toURL())
BuildConfig.groovy is used for compile, doc and etc.
Config.groovy is for settings that are used when the application is running.
So the Config.groovy is packaged in war, BuildConfig.groovy is not.
foo.bar.hello = "world"
It is import to have the quotes. The property values can be any valid Groovy type, strings, integers, or arbitrary objects.
Some implicit variables can not be used:
userHome home directory for the account that is running the grails
grailsHome
appName application name as it appears in application.properties
appVersion version in application.properties
BuildConfig.groovy is only available from command script via grailsSettings.config
Config.groovy is via grailsApplication in controllers
def recipient = grailsApplication.config.foo.bar.hello
And it can be easily injected into services.
class MyService{
def grailsApplication
String greeting(){
def recipient = grailsApplication.config.foo.bar.hello
…snip...
}
}
4.1.1 Built in options
Runtime Settings
grails.config.location The location of properties files can be set to other class path or userHome place.
http://grails.org/doc/latest/guide/single.html#configExternalized
grails.war.dependencies Manage the jars in war.
4.1.2 Logging
The Basics
log4j setting in Config.groovy
Logging Levels
1. off
2. fatal
3. error
4. warn
5. info
6. debug
7. trace
8. all
Loggers
class MyClass {
private static final log = LogFactory.getLog(this)
…snip…
}
The Root Logger
log4j = {
appenders {
file name: 'file', file:'/var/logs/mylog.log'
}
root{
debug 'stdout', 'file'
}
}
The root logger will log to 2 appenders. The default 'stdout' (console) apppender and file appender.
These are the default available appenders.
jdbc JDBCAppender
console ConsoleAppender
file FileAppender
rollingFile RollingFileAppender
Environment-specific configuration
// other shared config
info "grails.app.controller"
environments {
production {
// Override previous setting for 'grails.app.controller'
error "grails.app.controllers"
}
}
4.1.3 GORM
grails.gorm.failOnError=true
grails.gorm.autoFlush=true
4.2 Environments
Per Environment Configuration
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"
}
}
}Packaging and Running for Different Environments
>grails [envrionment] [command name]
references:
http://sillycat.iteye.com/blog/1567542
http://sillycat.iteye.com/blog/1074642
http://www.grails.org/tutorials?offset=0&max=10
https://github.com/grails-samples
http://grails.org/doc/latest/guide/index.html
http://grails.org/doc/latest/guide/conf.html
发表评论
-
NodeJS12 and Zlib
2020-04-01 07:44 476NodeJS12 and Zlib It works as ... -
Traefik 2020(1)Introduction and Installation
2020-03-29 13:52 337Traefik 2020(1)Introduction and ... -
Private Registry 2020(1)No auth in registry Nginx AUTH for UI
2020-03-18 00:56 436Private Registry 2020(1)No auth ... -
Buffer in NodeJS 12 and NodeJS 8
2020-02-25 06:43 385Buffer in NodeJS 12 and NodeJS ... -
NodeJS ENV Similar to JENV and PyENV
2020-02-25 05:14 479NodeJS ENV Similar to JENV and ... -
Prometheus HA 2020(3)AlertManager Cluster
2020-02-24 01:47 424Prometheus HA 2020(3)AlertManag ... -
Serverless with NodeJS and TencentCloud 2020(5)CRON and Settings
2020-02-24 01:46 337Serverless with NodeJS and Tenc ... -
GraphQL 2019(3)Connect to MySQL
2020-02-24 01:48 248GraphQL 2019(3)Connect to MySQL ... -
GraphQL 2019(2)GraphQL and Deploy to Tencent Cloud
2020-02-24 01:48 452GraphQL 2019(2)GraphQL and Depl ... -
GraphQL 2019(1)Apollo Basic
2020-02-19 01:36 328GraphQL 2019(1)Apollo Basic Cl ... -
Serverless with NodeJS and TencentCloud 2020(4)Multiple Handlers and Running wit
2020-02-19 01:19 314Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(3)Build Tree and Traverse Tree
2020-02-19 01:19 319Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(2)Trigger SCF in SCF
2020-02-19 01:18 294Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(1)Running with Component
2020-02-19 01:17 312Serverless with NodeJS and Tenc ... -
NodeJS MySQL Library and npmjs
2020-02-07 06:21 288NodeJS MySQL Library and npmjs ... -
Python Library 2019(1)requests and aiohttp
2019-12-18 01:12 261Python Library 2019(1)requests ... -
NodeJS Installation 2019
2019-10-20 02:57 574NodeJS Installation 2019 Insta ... -
Monitor Tool 2019(2)Monit on Multiple Instances and Email Alerts
2019-10-18 10:57 266Monitor Tool 2019(2)Monit on Mu ... -
Sqlite Database 2019(1)Sqlite3 Installation and Docker phpsqliteadmin
2019-09-05 11:24 368Sqlite Database 2019(1)Sqlite3 ... -
Supervisor 2019(2)Ubuntu and Multiple Services
2019-08-19 10:53 371Supervisor 2019(2)Ubuntu and Mu ...
相关推荐
《Grails 2 的终极指南》是一本深入探讨Grails框架精髓的专业书籍,该书以英文撰写,旨在为读者提供全面、深入的Grails框架学习资料。Grails框架基于Groovy语言,是一种高度动态、敏捷的Java应用开发框架,它简化了...
随书附带的代码库"The_definitive_guide_to_Grails2_code.zip"包含了书中示例项目的源代码,这有助于读者通过实际操作加深对理论知识的理解。读者可以按照书中的指导运行这些代码,跟随作者的脚步逐步学习Grails开发...
[Apress] The Definitive Guide to Grails 2 (E-Book) ☆ 出版信息:☆ [作者信息] Jeff Scott Brown, Graeme Rocher [出版机构] Apress [出版日期] 2013年01月23日 [图书页数] 360页 [图书语言] 英语 [图书...
Grails Persistence with GORM and GSQL
通过以上章节的总结,我们可以看到 Grails:A Quick-Start Guide 不仅涵盖了 Grails 的基础知识,还提供了实际项目开发的经验分享。无论是初学者还是有一定经验的开发者,都能从这本书中获得有价值的信息,帮助他们在...
### Grails 2 快速入门指南核心知识点详解 #### 一、Grails框架简介与特点 Grails 是一个基于Groovy语言的全栈式的Java Web应用开发框架,它极大地简化了开发流程,并且能够快速地搭建出高性能的应用程序。本书...
grails-2
The Definitive Guide to Grails 2nd Edition.pdf
《The Definitive Guide to Grails 2》是关于Grails框架的一本权威指南,它为读者提供了深入理解和使用Grails 2开发Web应用程序所需的知识。Grails是一种基于Groovy语言的开源全栈式Web应用框架,它借鉴了Ruby on ...
Java web development is notoriously tedious, ... This book will get you up and running with Grails by putting it to use in constructing an original, working application from start to finish. Book Details
### Grails 2: A Quick-Start Guide #### 书籍概览 《Grails 2:快速入门指南》是一本专为希望快速掌握Grails框架的开发者编写的实用指南。本书由Dave Klein与Ben Klein共同编写,通过一个逐步迭代的小项目来介绍...
2. **GORM(Grails Object Relational Mapping)**: GORM 是Grails的ORM框架,提供了与数据库交互的能力,支持关系型数据库,如MySQL、PostgreSQL等。它提供了CRUD操作,以及事务管理和动态查询。 3. **插件系统**...