grails config文件读取properties文件

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)