5.3.2 JNDI DataSources 2.4.4

See the light - agile, industrial strength, rapid web application development made easy

(Quick Reference) # 5.3.2 JNDI DataSources - Reference Documentation Authors: Graeme Rocher, Peter Ledbrook, Marc Palmer, Jeff Brown, Luke Daley, Burt Beckwith, Lari Hotari Version: 2.4.4 ## 5.3.2 JNDI DataSources #### Referring to a JNDI DataSource Most Java EE containers supply `DataSource` instances via Java Naming and Directory Interface (JNDI). Grails supports the definition of JNDI data sources as follows:
    dataSource {
        jndiName = "java:comp/env/myDataSource"
    }
The format on the JNDI name may vary from container to container, but the way you define the `DataSource` in Grails remains the same. #### Configuring a Development time JNDI resource The way in which you configure JNDI data sources at development time is plugin dependent. Using the Tomcat plugin you can define JNDI resources using the `grails.naming.entries` setting in `grails-app/conf/Config.groovy`:
    grails.naming.entries = [
        "bean/MyBeanFactory": [
            auth: "Container",
            type: "com.mycompany.MyBean",
            factory: "org.apache.naming.factory.BeanFactory",
            bar: "23"
        ],
        "jdbc/EmployeeDB": [
            type: "javax.sql.DataSource", //required
            auth: "Container", // optional
            description: "Data source for Foo", //optional
            driverClassName: "org.h2.Driver",
            url: "jdbc:h2:mem:database",
            username: "dbusername",
            password: "dbpassword",
            maxActive: "8",
            maxIdle: "4"
        ],
        "mail/session": [
            type: "javax.mail.Session,
            auth: "Container",
            "mail.smtp.host": "localhost"
        ]
    ]
| Quick Reference (hide)