Reputation: 2555
I have a bean with a List property. As it's mentioned in the documentation you can easily inject List property to the bean using beans DSL:
def example = exampleBean(MyExampleBean) {
someProperty = [1, 2, 3]
}
It works in resources.groovy
, but if you do it in plugin's doWithSpring
closure - the same bean definition doesn't work.
Is that a Grails bug (I'm using Grails 3.3.3)? Are there any workarounds to make it work in the plugin?
Upvotes: 0
Views: 475
Reputation: 27220
See the project at https://github.com/jeffbrown/taraskahut.
The plugin descriptor at https://github.com/jeffbrown/taraskahut/blob/df3df67cb8a6dd24317f45aa51b6fff449b60ed1/helper/src/main/groovy/helper/HelperGrailsPlugin.groovy#L43-L48 contains the following:
Closure doWithSpring() { {->
exampleBean(MyExampleBean) {
someProperty = [1, 2, 3, 5, 8]
}
}
}
The BootStrap.groovy
in the app at https://github.com/jeffbrown/taraskahut/blob/df3df67cb8a6dd24317f45aa51b6fff449b60ed1/app/grails-app/init/app/BootStrap.groovy contains the following:
package app
import helper.MyExampleBean
class BootStrap {
MyExampleBean exampleBean
def init = { servletContext ->
log.debug "someProperty is ${exampleBean.someProperty}"
}
def destroy = {
}
}
Running the app demonstrates that the property initialization works as expected:
$ ./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
Upvotes: 1