What I'm trying to achieve is the equivalent Groovy DSL spring config of this:

<bean id="myBean" class="com.example.SomeBeanWithConstructorArgs">
        <bean class="com.example.InnerBean">
            <property name="someService" ref="someService"/>

According to the docs, you would just pass the constructor arguments to the bean defining method invocation inside the top level closure: beanName(type, constructor-args) // parens optional But what a need to pass is not a value, but a bean definition.

I know I could define the bean to be passed as contructor-arg as a top level, named bean, and then pass it to the other bean by using a ref, like this:

myNamedBean(com.example.InnerBean) {
    someService = ref('someService')

myBean(com.example.SomeBeanWithConstructorArgs, ref('myNamedBean'))

But I really need com.example.InnerBean to be an anonymous, inner bean.

Is there any way to achieve this?

Thanks in advance.

  • I have the same issue. If we cannot make 'InnerBean' to be anonymous, we will have too many beans defined on the top level. – William Wong Mar 4 '16 at 5:17

Your Answer


Browse other questions tagged or ask your own question.