我们正在从 Grails 2 迁移到 Grails 4。非常简化,我们的 application.groovy 是这样的:
def someVar = [:]
environments {
myGreatApp.brandMap = [
'dev.analyzor1.com': someVar
]
}
这会导致错误,抱怨未创建变量“someVar”。
ERROR --- [ restartedMain] o.s.boot.SpringApplication : Application run failed
io.micronaut.context.exceptions.ConfigurationException: Exception occurred reading configuration [application]: BUG! exception in phase 'class generation' in source unit 'Script1.groovy' tried to get a variable with the name someVar as stack variable, but a variable with this name was not created
at io.micronaut.context.env.groovy.GroovyPropertySourceLoader.processInput(GroovyPropertySourceLoader.java:53)
at io.micronaut.context.env.AbstractPropertySourceLoader.read(AbstractPropertySourceLoader.java:112)
at io.micronaut.context.env.AbstractPropertySourceLoader.loadProperties(AbstractPropertySourceLoader.java:97)
at io.micronaut.context.env.AbstractPropertySourceLoader.load(AbstractPropertySourceLoader.java:73)
at io.micronaut.context.env.AbstractPropertySourceLoader.load(AbstractPropertySourceLoader.java:59)
at io.micronaut.context.env.PropertySourceLoader.load(PropertySourceLoader.java:51)
at io.micronaut.context.env.DefaultEnvironment.loadPropertySourceFromLoader(DefaultEnvironment.java:608)
at io.micronaut.context.env.DefaultEnvironment.readPropertySourceList(DefaultEnvironment.java:541)
at io.micronaut.context.DefaultApplicationContext$RuntimeConfiguredEnvironment.readPropertySourceList(DefaultApplicationContext.java:675)
at io.micronaut.context.env.DefaultEnvironment.readPropertySources(DefaultEnvironment.java:463)
at io.micronaut.context.env.DefaultEnvironment.start(DefaultEnvironment.java:324)
at io.micronaut.context.DefaultApplicationContext$RuntimeConfiguredEnvironment.start(DefaultApplicationContext.java:647)
在将代码从 Config.groovy 和 DataSource.groovy 移动到 application.groovy 之后,我正在迁移一个大型应用程序,这样的事情已经结束。
是否有无法在 application.groovy 中声明和使用变量的解决方法?谢谢