如何在ratpack.groovy中使用ConfigData?

如何在ratpack.groovy中使用ConfigData?,groovy,ratpack,Groovy,Ratpack,我试图按照示例进行操作,但我发现“ratpack.config.ConfigData”中的“of”错误不能应用于IntelliJ IDEA中的“(groovy.lang.Closure) ratpack { bindings { // Create generic configuration. final ConfigData configData = ConfigData.of { ConfigDataBuilder builder ->

我试图按照示例进行操作,但我发现“ratpack.config.ConfigData”中的“of”错误不能应用于IntelliJ IDEA中的“(groovy.lang.Closure)

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

IntelliJ显示有关不兼容分配的检查警告。代码是有效的,当您运行应用程序时,它可以正常工作。如果检查显示为错误,您可能希望降低这些工作分配的报告级别。否则,您需要将闭包转换为
Action
,以使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>) ... ... //创建通用配置。 final ConfigData ConfigData=ConfigData.of({ConfigDataBuilder-> //设置配置属性。 //我们可以使用yaml、json和其他 //要读取的ConfigDataBuilder方法 //来自其他来源的配置。 建筑道具( ['postgres.user':'postgres', 'postgres.password':'secret', “postgres.portNumber”:5432, 'postgres.databaseName':'postgres', 'postgres.serverName':'192.168.99.100']作为映射) builder.build() }(作为行动) ...
IntelliJ显示有关不兼容分配的检查警告。代码是有效的,当您运行应用程序时,它可以正常工作。如果检查显示为错误,您可能希望降低这些工作分配的报告级别。否则,您需要将闭包转换为
Action
,以使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>) ... ... //创建通用配置。 final ConfigData ConfigData=ConfigData.of({ConfigDataBuilder-> //设置配置属性。 //我们可以使用yaml、json和其他 //要读取的ConfigDataBuilder方法 //来自其他来源的配置。 建筑道具( ['postgres.user':'postgres', 'postgres.password':'secret', “postgres.portNumber”:5432, 'postgres.databaseName':'postgres', 'postgres.serverName':'192.168.99.100']作为映射) builder.build() }(作为行动) ...