- 浏览: 2552368 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
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-ConfigSlurper
ConfigSlurper is a utility class within Groovy. ConfigSlurper scripts support native Java types and are structured like a tree.
1. Common Usage
Properties for example:
log4j.appender.stdout = "org.apache.log4j.ConsoleAppender"
log4j.appender."stdout.layout"="org.apache.log4j.PatternLayout"
log4j.rootLogger="error,stdout"
log4j.logger.org.springframework="info,stdout"
log4j.additivity.org.springframework=false
Sample to load the config:
def config = new ConfigSlurper().parse(new File('myconfig.groovy').toURL())
assert "info,stdout" == config.log4j.logger.org.springframework
assert false == config.log4j.additivity.org.springframework
And the properties can be changed as follow:
log4j {
appender.stdout = "org.apache.log4j.ConsoleAppender"
appender."stdout.layout"="org.apache.log4j.PatternLayout"
rootLogger="error,stdout"
logger {
org.springframework="info,stdout"
}
additivity {
org.springframework=false
}
}
2. Converting to and from Java properties files
java.util.Properties props = //
def config = new ConfigSlurper().parse(props)
props = config.toProperties()
3. Merging configurations
def config1 = new ConfigSlurper().parse(..)
def config2 = new ConfigSlurper().parse(..)
config1 = config1.merge(config2)
4. Serializing a configuration to disk
Each config object implements the groovy.lang.Writable interface that allows you to write out the config to any java.io.Writer.
def config = new ConfigSlurper().parse(..)
new File("..").withWriter { writer ->
config.writeTo(writer)
}
5. Special "environments" Configuration
The properties file Sample.groovy is as follow:
sample {
foo = "default_foo"
bar = "default_bar"
}
environments {
development {
sample {
foo = "dev_foo"
}
}
test {
sample {
bar = "test_bar"
}
}
}
The loading of the properties:
def config = new ConfigSlurper("development").parse(new File('Sample.groovy').toURL())
assert config.sample.foo == "dev_foo"
assert config.sample.bar == "default_bar"
config = new ConfigSlurper("test").parse(new File('Sample.groovy').toURL())
assert config.sample.foo == "default_foo"
assert config.sample.bar == "test_bar"
6. How to Config Spring beans
spring configuration in my project
PropertyPlaceholderConfigurer implementation class from spring
<bean id="dataSource" destroy-method="close"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
jdbc.driverClassName=org.hsqldb.jdbcDriver
jdbc.url=jdbc:hsqldb:hsql:production:9002
jdbc.username=sa
jdbc.password=root
ConfigSluper configuration is as follow:
def normalize(s){
return s.toUpperCase()
}
jdbc{
driverClassName=org.hsqldb.jdbcDriver
url=jdbc:hsqldb:hsql:production:9002
username=normalize('sa')
password=normalize('root')
}
And we need to implements a new class named GroovyPlaceholderConfigurer
package com.sillycat.easywebflow.core;
import groovy.util.ConfigObject;
import groovy.util.ConfigSlurper;
import java.io.IOException;
import java.util.Properties;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
import org.springframework.core.io.Resource;
public class GroovyPlaceholderConfigurer extends PropertyPlaceholderConfigurer {
private Resource[] locations;
protected void loadProperties(Properties props) throws IOException {
ConfigObject configObject = new ConfigObject();
ConfigSlurper configSlurper = new ConfigSlurper();
for (Resource location : locations) {
configObject.merge(configSlurper.parse(location.getURL()));
}
props.putAll(configObject.toProperties());
}
public void setLocations(Resource[] locations) {
this.locations = locations;
}
public void setLocation(Resource location) {
this.locations = new Resource[] { location };
}
}
<bean class="com.sillycat.easywebflow.core.GroovyPlaceholderConfigurer">
<property name="ignoreResourceNotFound" value="true" />
<property name="locations">
<list>
<value>classpath:config.groovy</value>
<value>classpath:config.properties</value>
<value>classpath:config2.groovy</value>
</list>
</property>
</bean>
The latest config2.groovy will overwrite the config.groovy/config.properties from my testing during merging process. But we need to change the style of config file content as follow:
//################################################
//# velocity path
//################################################
velocity.file.path="file://d:/work/easy/easywebflow"
references:
http://groovy.codehaus.org/ConfigSlurper
http://jroller.com/0xcafebabe/entry/using_groovy_configslurper_to_configure
ConfigSlurper is a utility class within Groovy. ConfigSlurper scripts support native Java types and are structured like a tree.
1. Common Usage
Properties for example:
log4j.appender.stdout = "org.apache.log4j.ConsoleAppender"
log4j.appender."stdout.layout"="org.apache.log4j.PatternLayout"
log4j.rootLogger="error,stdout"
log4j.logger.org.springframework="info,stdout"
log4j.additivity.org.springframework=false
Sample to load the config:
def config = new ConfigSlurper().parse(new File('myconfig.groovy').toURL())
assert "info,stdout" == config.log4j.logger.org.springframework
assert false == config.log4j.additivity.org.springframework
And the properties can be changed as follow:
log4j {
appender.stdout = "org.apache.log4j.ConsoleAppender"
appender."stdout.layout"="org.apache.log4j.PatternLayout"
rootLogger="error,stdout"
logger {
org.springframework="info,stdout"
}
additivity {
org.springframework=false
}
}
2. Converting to and from Java properties files
java.util.Properties props = //
def config = new ConfigSlurper().parse(props)
props = config.toProperties()
3. Merging configurations
def config1 = new ConfigSlurper().parse(..)
def config2 = new ConfigSlurper().parse(..)
config1 = config1.merge(config2)
4. Serializing a configuration to disk
Each config object implements the groovy.lang.Writable interface that allows you to write out the config to any java.io.Writer.
def config = new ConfigSlurper().parse(..)
new File("..").withWriter { writer ->
config.writeTo(writer)
}
5. Special "environments" Configuration
The properties file Sample.groovy is as follow:
sample {
foo = "default_foo"
bar = "default_bar"
}
environments {
development {
sample {
foo = "dev_foo"
}
}
test {
sample {
bar = "test_bar"
}
}
}
The loading of the properties:
def config = new ConfigSlurper("development").parse(new File('Sample.groovy').toURL())
assert config.sample.foo == "dev_foo"
assert config.sample.bar == "default_bar"
config = new ConfigSlurper("test").parse(new File('Sample.groovy').toURL())
assert config.sample.foo == "default_foo"
assert config.sample.bar == "test_bar"
6. How to Config Spring beans
spring configuration in my project
PropertyPlaceholderConfigurer implementation class from spring
<bean id="dataSource" destroy-method="close"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
jdbc.driverClassName=org.hsqldb.jdbcDriver
jdbc.url=jdbc:hsqldb:hsql:production:9002
jdbc.username=sa
jdbc.password=root
ConfigSluper configuration is as follow:
def normalize(s){
return s.toUpperCase()
}
jdbc{
driverClassName=org.hsqldb.jdbcDriver
url=jdbc:hsqldb:hsql:production:9002
username=normalize('sa')
password=normalize('root')
}
And we need to implements a new class named GroovyPlaceholderConfigurer
package com.sillycat.easywebflow.core;
import groovy.util.ConfigObject;
import groovy.util.ConfigSlurper;
import java.io.IOException;
import java.util.Properties;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
import org.springframework.core.io.Resource;
public class GroovyPlaceholderConfigurer extends PropertyPlaceholderConfigurer {
private Resource[] locations;
protected void loadProperties(Properties props) throws IOException {
ConfigObject configObject = new ConfigObject();
ConfigSlurper configSlurper = new ConfigSlurper();
for (Resource location : locations) {
configObject.merge(configSlurper.parse(location.getURL()));
}
props.putAll(configObject.toProperties());
}
public void setLocations(Resource[] locations) {
this.locations = locations;
}
public void setLocation(Resource location) {
this.locations = new Resource[] { location };
}
}
<bean class="com.sillycat.easywebflow.core.GroovyPlaceholderConfigurer">
<property name="ignoreResourceNotFound" value="true" />
<property name="locations">
<list>
<value>classpath:config.groovy</value>
<value>classpath:config.properties</value>
<value>classpath:config2.groovy</value>
</list>
</property>
</bean>
The latest config2.groovy will overwrite the config.groovy/config.properties from my testing during merging process. But we need to change the style of config file content as follow:
//################################################
//# velocity path
//################################################
velocity.file.path="file://d:/work/easy/easywebflow"
references:
http://groovy.codehaus.org/ConfigSlurper
http://jroller.com/0xcafebabe/entry/using_groovy_configslurper_to_configure
发表评论
-
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 478NodeJS 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 370Supervisor 2019(2)Ubuntu and Mu ...
相关推荐
标题中的"grails-fck-editor-0.3.zip_grails_grails-fck-editor"表明这是一个与Grails框架相关的插件,具体来说是FCKeditor的一个版本。FCKeditor是一款广泛使用的开源富文本编辑器,它允许用户在网页上创建和编辑...
在 `grails-app/domain` 创建 `User.groovy` 文件定义用户类,然后在 `grails-app/controllers/UserController.groovy` 编写控制器,处理用户的注册、登录等操作。在 `grails-app/views/user` 下创建相应的 GSP 页面...
groovy-grails-tool-suite-3.6.4.RELEASE-e4.4.2-win32-x86_64.part1 共两个压缩包,解压后将扩展名.zip.bak改为.zip再次解压。
`grails-doc-CN-1.0.rar` 文件包含的是 Grails 1.0 版本的中文参考文档,对于那些不熟悉英文文档或者想要深入了解 Grails 的中文用户来说,这是一个极其宝贵的资源。 文档主要涵盖以下几个关键知识点: 1. **...
groovy-grails-tool-suite-3.6.4.RELEASE-e4.4.2-win32-x86_64.part2 共两个包,解压后需要将扩展名.zip.bak改名为.zip重新解压。 http://dist.springsource.com/release/STS/3.8.1.RELEASE/dist/ e4.6/spring-tool-...
总之,"grails-datastore-gorm-plugin-support-2.0.4.RELEASE.zip"提供了一个宝贵的资源,让开发者有机会学习和实践Grails的ORM功能和Android的MVC设计模式。无论是对Grails框架的探索,还是对Android开发的深化,这...
在`Grails` 中,`Grails-Quartz` 插件提供了集成`Quartz` 的能力,使得开发者可以在`Grails` 应用中方便地安排和执行周期性任务。 **1. QuartzGrailsPlugin.groovy** 这个文件是`Grails` 插件的核心配置文件,其中...
在解压后的`grails-core-master`目录中,我们可以看到Grails的核心模块组织结构。通常,一个开源项目的源码结构反映了它的设计思路和功能划分。`src/main/groovy`包含了主要的源代码,`src/test/groovy`用于存放测试...
Grails是一种基于Groovy语言的开源Web应用框架,它构建在Spring Boot之上,旨在提高开发者的生产力和灵活性。Grails 2.3.6是该框架的一个特定版本,发布于2014年,提供了许多改进和新特性,旨在优化开发流程。 1. *...
本文将深入探讨Grails的中文文档以及“grails-fckeditor-0.9.5”插件的相关知识点。 一、Grails框架基础 1. Groovy语言:Grails的基础是Groovy,这是一种面向对象、动态类型的编程语言,语法简洁且与Java高度兼容...
Grails是一套用于快速Web应用开发的开源框架,它基于Groovy编程语言,并构建于Spring、Hibernate等开源框架之上,是一个高生产力一站式框架。 Grails这个独特的框架被视为是提升工程师生产效率的动态工具,因为其...
这个名为"grails-web-url-mappings-2.5.4.zip"的压缩包包含了Grails 2.5.4版本中的Web URL映射相关代码,让我们深入探讨这一关键组件。 Grails是一个基于Groovy语言的全栈式Java web框架,其设计理念是“简洁、生产...
Grails 4 ships with the following dependency upgrades: Groovy 2.5.6 GORM 7 and Hibernate 5.4 (now the default version of Hibernate for new applications) Spring Framework 5.1.5 Spring Boot 2.1.3 ...
`grails-docs-2.0.0`是Grails 2.0.0版本的官方文档,包含了丰富的指南、API参考以及国际化资源,对于学习和掌握Grails 2.0.0至关重要。 首先,`index.html`是文档的主页,通常会包含目录、介绍性内容以及如何开始的...
grails-spring-websocket ils子 2.4.x 3.2.7+ 2.5.x 4.0.0+ 安装 要将插件安装到Grails应用程序中,请将以下行添加到build.gradle依赖项部分: implementation "org.grails.plugins:grails-spring-websocket:...
《Grails框架API文档详解——基于grails-docs-1.0》 Grails是一种基于Groovy语言的开源Web应用框架,它简化了Java开发,提供了丰富的功能和强大的工具,深受开发者喜爱。本文将深入探讨grails-docs-1.0版本的API...
本文将详细探讨“grails-acegi-0.2.1.zip”这个插件,它是Grails框架中用于实现权限管理的Spring插件的一个早期版本。 Acegi Security是Spring框架的一个扩展,它提供了一套全面的、灵活的安全性解决方案。在Grails...
2. **创建新项目**:通过`grails create-app`命令创建项目,理解`grails-app`目录结构。 3. **编写Domain Class**:学习如何定义领域类,包括关系映射和验证规则。 4. **创建Controller**:了解如何创建控制器,处理...
4. `docs`、`grails-app`、`src`、`scripts`和`lib`目录则分别包含了插件的文档、应用代码、源代码、脚本以及依赖的库文件。 Grails Acegi 0.5插件提供了以下主要功能: - **用户认证**:支持多种认证机制,如...