如何在ratpack.groovy中使用ConfigData?
How to use ConfigData in ratpack.groovy?
我正在尝试按照示例进行操作 Ratpacked: Using PostgreSQL Database,但我在 IntelliJ IDEA 中收到错误 'of' in 'ratpack.config.ConfigData' can not be applied to '(groovy.lang.Closure<ratpack.config.ConfigDataBuilder>)'
。
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<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>)
...
我正在尝试按照示例进行操作 Ratpacked: Using PostgreSQL Database,但我在 IntelliJ IDEA 中收到错误 'of' in 'ratpack.config.ConfigData' can not be applied to '(groovy.lang.Closure<ratpack.config.ConfigDataBuilder>)'
。
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<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>) ...