Harish Mallikarjuna
Harish Mallikarjuna

Reputation: 93

Not able to create a JNDI object in grails

How do I do a lookup in grails? A jndi lookup should be simple enough, but I find confusing information about context.xml, adding "grails.naming.entries" in Config.xml, creating a jndi-lookup bean in resources.groovy - all of the combinations I've tried so far have been fruitless. It is able to take the JNDI if we give it in context.xml of tomcat. So if i deploy the war inside tomcat i do not get any exception.

my config.groovy

grails.naming.entries = [
    "java:comp/env/bonitaDS": [
            type: 'javax.sql.DataSource',
            auth: 'Container',
            description: 'Main datasource',
            url: "jdbc:mysql://localhost/bonita?useUnicode=yes&characterEncoding=UTF-8",
            username: "",
            password: "",
            driverClassName: "com.mysql.jdbc.Driver",//"com.mysql.jdbc.jdbc2.optional.MysqlXADataSource",
            maxActive: "8",
            maxIdle: "4"
    ],

    "java:comp/env/bonitaSequenceManagerDS": [
            type: 'javax.sql.DataSource',
            auth: 'Container',
            description: 'Main datasource',
            url: 'jdbc:mysql://localhost/bonita?useUnicode=yes&characterEncoding=UTF-8',
            username: "root",
            password: "root",
            driverClassName: 'com.mysql.jdbc.Driver',
            maxConnectionsPerPartition: "2",
            minConnectionsPerPartition: "1",
            partitionCount: "1",
            acquireIncrement: "5",
            statementsCacheSize: "100",
            releaseHelperThreads: "3"
    ],

    "java:comp/UserTransaction": [
            type: 'com.atomikos.icatch.jta.UserTransactionFactory'
    ]
]

My context.xml file inside conf folder of tomcat

<Resource name="bonitaSequenceManagerDS"
          auth="Container"
          type="javax.sql.DataSource"
          maxActive="17"
          minIdle="5"
          maxWait="10000"
          initialSize="3"
          maxPoolSize="15"
          minPoolSize="3"
          maxConnectionAge="0"
          maxIdleTime="1800"
          maxIdleTimeExcessConnections="120"
          idleConnectionTestPeriod="30"
          acquireIncrement="3"
          validationQuery="SELECT 1"
          validationInterval="30000"
          testConnectionOnCheckout="true"
          removeAbandoned="true"
          logAbandoned="true"
          username=""
          password=""
          driverClassName="com.mysql.jdbc.Driver"
          url="jdbc:mysql://localhost:3306/bonita?dontTrackOpenResources=true&amp;useUnicode=true&amp;characterEncoding=UTF-8&amp;autoReconnect=true"/>

<Resource name="bonitaDS" 
          auth="Container" 
          type="javax.sql.DataSource"
          factory="bitronix.tm.resource.ResourceObjectFactory"       
          uniqueName="jdbc/bonitaDSXA" />

The error:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager' defined in file [C:\bonita-home\server\platform\conf\services\cfg-bonita-transaction-api-impl.xml]: Invocation of init method failed; nested exception is javax.naming.NameNotFou ion: Name [java:comp/UserTransaction] not bound; 2 bindings: [java:comp/env/bonitaDS,java:comp/env/bonitaSequenceManagerDS] (Use --stacktrace to see the full trace)

I get the following startup exception when running the test-app and also get the same exception during run time when using run-app using Grails 2.4.2

Upvotes: 1

Views: 594

Answers (1)

Hussain Fakhruddin
Hussain Fakhruddin

Reputation: 3272

This is how we do it in Datasource.groovy

dataSource {

   jndiName = "java:comp/env/jdbc/bonitaSequenceManagerDS"
}

Upvotes: 1

Related Questions