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 config文件读取properties文件
最新推荐文章于 2025-11-20 15:56:46 发布
本文介绍了一种在Grails框架中动态配置数据源的方法。通过读取外部属性文件中的数据库连接参数,如URL、用户名、密码等,并将其应用于生产环境的数据源配置中。此过程涉及属性文件的加载、读取及解析。
227

被折叠的 条评论
为什么被折叠?



