2017-04-21 34 views
0

我试图按照示例Ratpacked: Using PostgreSQL Database,但我得到IntelliJ IDEA中的错误'of' in 'ratpack.config.ConfigData' can not be applied to '(groovy.lang.Closure<ratpack.config.ConfigDataBuilder>)'如何在ratpack.groovy中使用ConfigData?

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 
    } 
} 

回答

2

IntelliJ显示关于不兼容分配的检查警告。该代码是有效的,当你运行应用程序时,它可以正常工作。如果检查显示为错误,则可能需要降低这些分配的报告级别。否则,你需要将关闭到Action<ConfigDataBuilder>使IntelliJ快乐,但它也混乱ratpack.groovy。代码正确铸造然后:

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