MyBatis JDNI Connection problem

976 views
Skip to first unread message

Javier Arenales Castrodeza

unread,
May 25, 2015, 11:27:14 AM5/25/15
to mybati...@googlegroups.com
Hi guys,

I'd like to connect MyBatis to JBoss Datasource by JNDI.

My mybatis configuration xml file contains the next:

<environment id="development">
<transactionManager type="JDBC"/>
<dataSource type="JNDI">
  <property name="data_source" value="java:jboss/datasources/sch_entitlement_db" />
</dataSource>
</environment>

With this configuration, I get the next error:

### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.datasource.DataSourceException: There was an error configuring JndiDataSourceTransactionPool. Cause: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
 at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:26) ~[mybatis-3.2.8.jar:3.2.8]
 at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:54) ~[mybatis-3.2.8.jar:3.2.8]


I've tried as well with this, with the same result:

<environment id="development">
<transactionManager type="JDBC"/>
<dataSource type="JNDI">
<property name="initial_context" value="org.jboss.naming.remote.client.InitialContextFactory" />
  <property name="data_source" value="java:jboss/datasources/sch_entitlement_db" />
</dataSource>
</environment>

What do I have to set in "initial_context" parameter? What am I doing wrong?

Thanks in advance.

Javier

Guy Rouillier

unread,
May 25, 2015, 8:46:58 PM5/25/15
to mybati...@googlegroups.com
You don't say what your runtime environment is.  I use exactly what you show in a Tomcat server without issue.  Your DB URL contains "jboss", so I'm guessing you are running in either JBoss or WildFly.  In that case, you want a MANAGED transaction manager.  See here for an example: https://developer.jboss.org/wiki/MyBatisIBatisAndJBossAS7.
 
Search "mybatis jboss jndi" for other examples.
 
--
Guy Rouillier
--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mybatis-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



Avast logo

This email has been checked for viruses by Avast antivirus software.
www.avast.com


Ikchan Sim

unread,
May 25, 2015, 10:25:00 PM5/25/15
to mybati...@googlegroups.com
Check out the WAS(JBoss) JNDI settings.

For example, JNDI settings must be in the 'data_source' names in the server.xml file.

Muhammad Edwin

unread,
May 25, 2015, 11:32:18 PM5/25/15
to mybati...@googlegroups.com

Im using this for tomcat dbcp

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
    <environments default="development">


        <environment id="development">
            <transactionManager type="JDBC"/>
            <dataSource type="JNDI">

                <property name="data_source" value="java:/comp/env/jdbc/test"/>
            </dataSource>
        </environment>
    </environments>
</configuration>

And it runs well. On JBoss should be the same, perhaps the only difference is on jndi name. Also make sure you set your jndi on web.xml and on jboss standalone.xml (or standalone-ha.xml)

---
sent from my mobile device.

On May 26, 2015 9:25 AM, "Ikchan Sim" <plusp...@gmail.com> wrote:
Check out the WAS(JBoss) JNDI settings.

For example, JNDI settings must be in the 'data_source' names in the server.xml file.

--
Reply all
Reply to author
Forward
0 new messages