2017-08-18 18 views
0

これはプロパティファイルを読み込んでいるクラスで、2つのファイルがあります。Config.groovyメソッドとCall.groovyがあります。ここでは、設定からメソッドを呼び出してリターンを期待しています。インスタンス化されたGroovy String戻り型

Config.groovy

class Config 
{ 

public methodParse { 

    Properties properties = new Properties() 

    File propertiesFile = new File('src/main/resources/application.properties') 
    propertiesFile.withInputStream 
     { 
      properties.load(it) 
     } 

    String value = properties."$name" 
    return value 
    } 
} 

def config = new Config() 
config.methodParse "environments.local.logfile" 
println (config.methodParse()); 

load.groovyにはどうすればload.groovyパラメータを渡し、その後、受信したものを印刷しているのですか?

答えて

0

あなたは

class Config 
    { 

     public String methodParse (String name) 
     { 

      Properties properties = new Properties() 

      File propertiesFile = new File('src/main/resources/application.properties') 
      propertiesFile.withInputStream 
      { 
       properties.load(it) 
      } 

      String value = properties."$name" 
      return value 
     } 
    } 

    def config = new Config() 
    the_value =config.methodParse("environments.local.logfile") 
    println (conf_value); 
+0

これは私がそれを実行したときに得られるものです。groovy.lang.MissingPropertyException:いいえそのようなプロパティ:クラスのためのretun: –

0

私はあなたを正しく理解していますか?

class Config { 
    public methodParse(String name) { 
     Properties properties = new Properties() 
     File propertiesFile = new File('src/main/resources/application.properties') 
     propertiesFile.withInputStream { 
      properties.load(it) 
     } 
     properties."$name" 
    } 
} 

使用法:私はこれは私がデフ設定

をやったことあるそれを修正することができました

def config = new Config() 
    config.methodParse "environments.local.logfile" 
0

ような何かを試みることができる 構文エラーを無視します=新しいConfig() 文字列conf_value = config.methodPa rse( "environments.local.logfile") println conf_value

関連する問題