springgrailsspring-groovy-config

"Manually" creating beans with Grails BeanBuilder or Spring GenericGroovyApplicationContext


I have a class with complicated creation logic (e.g. uses builder). Back in 2000, because XML is rigid and not a programming language, I couldn't code the creation logic in it, so I encapsulated it in a FactoryBean.

Then the blessed JavaConfig came (thank you, @cbeams) and threw FactoryBean to the dumpster of history.

Since GroovyConfig is an additional step forward (not only a true programming language for the configuration, but also with DSL), I was sure to find a simple and elegant way to code my way though complicated creation logic, but didn't find any mention of an ability to do so?!

I understand that GroovyConfig is more or less taken verbatim from Grails BeanBuilder, so maybe if there is a way to do it there it will also work in GroovyConfig (fingers crossed).

Please tell me I am missing something obvious and don't have to use FactoryBean again!

Sleeping on it, I think the answer is no. I am adding an answer (still hoping it will get horribly downvoted as wrong one). Please prove me wrong!


Solution

  • Thinking about it, it looks like the answer is "no". It looks like I can't manage without FactoryBean, that's why: