2017-04-21 2 views
0

Ich versuche, mit dem Beispiel Ratpacked: Using PostgreSQL Database zu folgen, aber ich bekomme den Fehler 'of' in 'ratpack.config.ConfigData' can not be applied to '(groovy.lang.Closure<ratpack.config.ConfigDataBuilder>)' in IntelliJ IDEA.Wie verwende ich ConfigData in ratpack.groovy?

ratpack { 
    bindings { 
     // Create generic configuration. 
     final ConfigData configData = ConfigData.of { ConfigDataBuilder builder -> 
      // Set configuration properties. 
      // We can use the yaml, json and other 
      // ConfigDataBuilder methods to read 
      // configuration from other sources. 
      builder.props(
        ['postgres.user'  : 'postgres', 
        'postgres.password' : 'secret', 
        'postgres.portNumber' : 5432, 
        'postgres.databaseName': 'postgres', 
        'postgres.serverName' : '192.168.99.100']) 
      builder.build() 
     } 

     // Create instance of PostgresConfig 
     // that is used for the 
     // configurable module PostgresModule. 
     bindInstance PostgresConfig, configData.get('/postgres', PostgresConfig) 
     // Initialise module to create DataSource. 
     module PostgresModule 

     // Initialize SqlModule to provide 
     // Groovy SQL support in our application. 
     module SqlModule 
    } 
} 

Antwort

2

IntelliJ zeigt eine Inspektion über inkompatible Zuweisungen zu warnen. Der Code ist gültig und wenn Sie die Anwendung ausführen, funktioniert es einfach. Wenn die Inspektion als Fehler angezeigt wird, möchten Sie möglicherweise die Berichtsebene für diese Zuordnungen verringern. Andernfalls müssten Sie den Verschluss auf Action<ConfigDataBuilder> umwandeln, um IntelliJ glücklich zu machen, aber es wird auch die ratpack.groovy verstopft. Der Code mit richtigem Gießen ist dann:

 
... 
     // Create generic configuration. 
     final ConfigData configData = ConfigData.of({ ConfigDataBuilder builder -> 
      // Set configuration properties. 
      // We can use the yaml, json and other 
      // ConfigDataBuilder methods to read 
      // configuration from other sources. 
      builder.props(
        ['postgres.user'  : 'postgres', 
        'postgres.password' : 'secret', 
        'postgres.portNumber' : 5432, 
        'postgres.databaseName': 'postgres', 
        'postgres.serverName' : '192.168.99.100'] as Map<String, String>) 
      builder.build() 
     } as Action<ConfigDataBuilder>) 
...