---
title: "Configure a bean with factory using Spring DSL"
author: "boogie"
date: "2008-05-22T17:38:42Z"
tags: []
slug: "configure-a-bean-with-factory-using-spring-dsl"
draft: false
lastmod: "2008-05-22T17:38:42Z"
id: 195753
url: "https://boogie.iteye.com/blog/195753"
---

1、How do I configure a bean like this using **Spring** **DSL** ?

```
    <bean id="mailSession" class="javax.mail.Session" factory-method="getInstance">
        <constructor-arg>
            <props>
                <prop key="mail.smtp.auth">true</prop>
            </props>
        </constructor-arg>
        <constructor-arg ref="smtpAuthenticator" />
    </bean>
```

 2、 To answer my own question it should look like this:

```
beans = {
  def props = new Properties()
  props.setProperty('mail.smtp.auth', 'true')

  mailSession(javax.mail.Session, props, ref('smtpAuthenticator')) { bean ->
     bean.factoryMethod = 'getInstance'
  }
  ...
}
```

   Note that using Properties makes the code less tidy than if the   property accepted a Map.