grails config文件读取properties文件
程序员文章站
2022-05-23 15:53:54
...
environments {
production {
dataSource {
def dbConfLoc = System.getProperty('gis.config.location', null)
if (!dbConfLoc) {
dbConfLoc = "test.properties"
}
grails.config.locations = [ dbConfLoc ]
def props = new Properties()
def f = new File(grails.config.locations[0])
if (f.exists()) {
props.load(f.newInputStream())
def freader = new FileReader(f);
def lnreader = new LineNumberReader(freader);
System.out.println props.getProperty("dataSource.url")+"======url";
dialect=props.getProperty("dataSource.dialect");
url=props.getProperty("dataSource.url");
username =props.getProperty("dataSource.username");
password =props.getProperty("dataSource.password");
driverClassName=props.getProperty("dataSource.driverClassName");
println username+"/"+password
while ((line = lnreader.readLine()) != null){
System.out.println("Line: " + lnreader.getLineNumber() + ": " + line);
}
freader.close();
lnreader.close();
}else{
println "找不到文件 gis.properties"
}
}
}
上一篇: 关于Grails的自定义TagLib
下一篇: Grails 1.3.7 小技巧汇总