Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Minor
-
Resolution: Fixed
-
Affects Version/s: 0.4
-
Fix Version/s: 0.6-RC1
-
Component/s: Configuration
-
Labels:None
Description
Bean properties aren't set when using BeanBuilder from within a Groovy script. BeanBuilder seems to work fine when used within a class (as in http://svn.grails.codehaus.org/browse/grails/trunk/grails/test/groovy/grails/spring/BeanBuilderTests.groovy?r=2213), but fails when used in a standalone script.
For example, I'm trying to recreate the Spring configuration from listing 1.8 of "Spring in Action" using the BeanBuilder. Here's the script:
package com.springinaction.chapter01.knight;
import org.springframework.context.ApplicationContext;
def bb = new grails.spring.BeanBuilder()
bb.beans {
quest(HolyGrailQuest) {}
knight(KnightOfTheRoundTable, "Bedivere") {
quest = quest
}
}
ApplicationContext ctx = bb.createApplicationContext()
Knight knight = ctx.getBean("knight")
knight.embarkOnQuest()
The quest property never gets set. Consequently, a NPE is thrown when trying to call the embark() method (within embarkOnQuest()).
Changing:
knight(KnightOfTheRoundTable, "Bedivere") { quest = quest }to:
knight(KnightOfTheRoundTable, "Bedivere") { delegate.quest = quest }Seemed to work for me (on a similar example, didn't actually try this one) using the latest version of Spring (2.1m2) and Grails head.
knight(KnightOfTheRoundTable, "Bedivere") { quest = quest }knight(KnightOfTheRoundTable, "Bedivere") { delegate.quest = quest }