0

我正在尝试遵循示例Ratpacked: Using PostgreSQL Database,但'of' in 'ratpack.config.ConfigData' can not be applied to '(groovy.lang.Closure<ratpack.config.ConfigDataBuilder>)'在 IntelliJ IDEA 中出现错误。

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

1 回答 1

2

IntelliJ 显示有关不兼容分配的检查警告。该代码是有效的,当您运行应用程序时它运行良好。如果检查显示为错误,您可能希望降低这些分配的报告级别。否则,您需要将闭包强制转换Action<ConfigDataBuilder>为使 IntelliJ 高兴,但它也会使ratpack.groovy. 正确转换的代码是:

...
        // 创建通用配置。
        final ConfigData configData = ConfigData.of({ ConfigDataBuilder builder ->
            // 设置配置属性。
            // 我们可以使用yaml、json等
            // ConfigDataBuilder 方法读取
            // 来自其他来源的配置。
            builder.props(
                    ['postgres.user':'postgres',
                     'postgres.password':'秘密',
                     'postgres.portNumber':5432,
                     'postgres.databaseName': 'postgres',
                     'postgres.serverName' : '192.168.99.100'] 作为 Map<String, String>)
            builder.build()
        } 作为 Action<ConfigDataBuilder>)
...
于 2017-04-21T14:06:59.120 回答