spring - Grails插件:将列表注入doWithSpring中的bean
问题描述
我有一个带有 List 属性的 bean。正如文档中提到的,您可以使用 beans DSL 轻松地将 List 属性注入 bean:
def example = exampleBean(MyExampleBean) {
someProperty = [1, 2, 3]
}
它适用于resources.groovy
,但如果你在插件的doWithSpring
闭包中这样做 - 相同的 bean 定义不起作用。
这是一个 Grails 错误(我使用的是 Grails 3.3.3)吗?是否有任何解决方法可以使其在插件中工作?
解决方案
请参阅https://github.com/jeffbrown/taraskahut上的项目。
Closure doWithSpring() { {->
exampleBean(MyExampleBean) {
someProperty = [1, 2, 3, 5, 8]
}
}
}
在https://github.com/jeffbrown/taraskahut/blob/df3df67cb8a6dd24317f45aa51b6fff449b60ed1/app/grails-app/init/app/BootStrap.groovyBootStrap.groovy
的应用程序中包含以下内容:
package app
import helper.MyExampleBean
class BootStrap {
MyExampleBean exampleBean
def init = { servletContext ->
log.debug "someProperty is ${exampleBean.someProperty}"
}
def destroy = {
}
}
运行应用程序表明属性初始化按预期工作:
$ ./gradlew app:bootRun
...
:app:processResources
:app:classes
:app:findMainClass
:app:bootRun
2018-11-06 13:19:52.983 DEBUG --- [ main] app.BootStrap
: someProperty is [1, 2, 3, 5, 8]
Grails application running at http://localhost:8080 in environment: development
推荐阅读
- c# - ADX:无法从 .NET sdk 提取带有 JSON 映射的数据
- angular - 如何映射服务器响应以获取错误和成功
- kubernetes - Kubernetes pod 提供不等量的流量
- c - 我不理解的 strtok() 行为
- jsf - JSF从没有显示的bean中设置inputText值
- kubernetes - Prometheus Alertmanager 是否能够区分事件和条件?
- java - 如何在android studio中从给定的mp3文件中获取音频数据
- android - Android Studio 中 Intentservice/coroutine/workmanager 中的后台数据更新
- r - 在ggplot中绘制多条线的功能
- akka - akka actor 可以在不同的情况下回复消息吗