欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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