2017-04-21 1 views
0

J'essaie de suivre avec l'exemple Ratpacked: Using PostgreSQL Database mais j'obtiens l'erreur 'of' in 'ratpack.config.ConfigData' can not be applied to '(groovy.lang.Closure<ratpack.config.ConfigDataBuilder>)' dans IntelliJ IDEA.Comment utiliser ConfigData dans 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 
    } 
} 

Répondre

2

IntelliJ affiche un avertissement d'inspection concernant les affectations incompatibles. Le code est valide et lorsque vous exécutez l'application, il fonctionne correctement. Si l'inspection est indiquée comme une erreur, vous pouvez réduire le niveau de déclaration pour ces affectations. Sinon, vous devrez lancer la fermeture à Action<ConfigDataBuilder> pour rendre IntelliJ heureux, mais il encombrera également le ratpack.groovy. Le code avec le casting approprié est alors:

 
... 
     // 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>) 
...