tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Vamsee Lakamsani <>
Subject Re: Using custom data source connection factory in JUnit
Date Wed, 04 Jun 2014 16:39:34 GMT
Getting close. It is calling my factory when I use the syntax you suggested but the .auth (and
a few more properties I have) are not getting through. When I look in the debugger when running
the unit test,  I just see the two standard ones (ServiceId and transactionManager). I see
all of them when debugging via TomEE. 

Here's is the line of code where I added the extra properties. Is there another way to pass
them in?

 p.put("myDs.auth", "Application");

FYI I use this line to create the embedded container:
EJBContainer.createEJBContainer(p).getContext().bind("inject", this);

On a related topic I have another issue that only shows up in them embedded container via
JUnit. To get there I skip the factory for now and specify all the properties to the data
source directly in the unit test code. It then gets to a point where it needs a MyBatis  SqlSessionFactory setup
using MyBatis CDI like this:

All of this works via TomEE but in the embedded container I get this exception. All of the
MyBatis CDI unit tests (in their git repo) use Weld/Weld JUnit runner. But given that this
works in TomEE I 'm hoping there is someway to get it to work in the embedded OpenEJB container
as well. 

SEVERE - The bean instance PolicyManager threw a system exception:org.mybatis.cdi.MybatisCdiConfigurationException:
There are no SqlSessionFactory producers properly configured.
org.mybatis.cdi.MybatisCdiConfigurationException: There are no SqlSessionFactory producers
properly configured.
at org.mybatis.cdi.CDIUtils.findSqlSessionFactory(
at org.mybatis.cdi.MyBatisBean.findSqlSessionManager(
at org.mybatis.cdi.MyBatisBean.create(
at org.apache.webbeans.component.third.ThirdpartyBeanImpl.create(
at org.apache.webbeans.context.DependentContext.getInstance(
at org.apache.webbeans.context.AbstractContext.get(
at org.apache.webbeans.container.BeanManagerImpl.getReference(
at org.apache.webbeans.container.BeanManagerImpl.getInjectableReference(
at org.apache.webbeans.inject.AbstractInjectable.inject(
at org.apache.webbeans.inject.InjectableField.doInjection(
at org.apache.webbeans.portable.InjectionTargetImpl.injectFields(
at org.apache.webbeans.portable.InjectionTargetImpl.inject(
at org.apache.webbeans.portable.InjectionTargetImpl.inject(
at org.apache.openejb.cdi.CdiEjbBean$EjbInjectionTargetImpl.inject(
at org.apache.openejb.BeanContext.inject(
at org.apache.openejb.BeanContext.newInstance(
at org.apache.openejb.core.singleton.SingletonInstanceManager.createInstance(
at org.apache.openejb.core.singleton.SingletonInstanceManager.access$100(
at org.apache.openejb.core.singleton.SingletonInstanceManager$
at org.apache.openejb.core.singleton.SingletonInstanceManager$
at org.apache.openejb.core.singleton.SingletonInstanceManager.getInstance(
at org.apache.openejb.core.singleton.SingletonInstanceManager.initialize(
at org.apache.openejb.core.singleton.SingletonInstanceManager.start(
at org.apache.openejb.core.singleton.SingletonContainer.start(
at org.apache.openejb.assembler.classic.Assembler.startEjbs(
at org.apache.openejb.assembler.classic.Assembler.createApplication(
at org.apache.openejb.assembler.classic.Assembler.createApplication(
at org.apache.openejb.OpenEjbContainer$Provider.createEJBContainer(
at javax.ejb.embeddable.EJBContainer.createEJBContainer(
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(
at sun.reflect.DelegatingMethodAccessorImpl.invoke(
at java.lang.reflect.Method.invoke(
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(
at org.junit.runners.model.FrameworkMethod.invokeExplosively(
at org.junit.internal.runners.statements.RunBefores.evaluate(
at org.junit.runners.ParentRunner.runLeaf(
at org.junit.runners.BlockJUnit4ClassRunner.runChild(
at org.junit.runners.BlockJUnit4ClassRunner.runChild(
at org.junit.runners.ParentRunner$
at org.junit.runners.ParentRunner$1.schedule(
at org.junit.runners.ParentRunner.runChildren(
at org.junit.runners.ParentRunner.access$000(
at org.junit.runners.ParentRunner$2.evaluate(

 From: Romain Manni-Bucau <>
To: "" <>; Vamsee Lakamsani <>

Sent: Wednesday, June 4, 2014 9:04 AM
Subject: Re: Using custom data source connection factory in JUnit

myDs = new://Resource?type=DataSource&class-name=....&factory-name=...

as properties should work

Romain Manni-Bucau
Twitter: @rmannibucau

2014-06-04 17:46 GMT+02:00 Vamsee Lakamsani <>:
> I have a resource defined like this in tomee.xml and it works fine from TomEE
> <Resource id=“myDS" type="javax.sql.DataSource"
>        factory-name="createJDBCDataSource" class-name=“my.CustomDataSourceFactory"
>         auth=Application
>         singleton = true
> </Resource>
> Now, I want to test this in JUnit using javax.ejb.embeddable.EJBContainer
> This example shows how to use Properties to initialize the data source.  But is there
any way I can just pass a javax.sql.DataSource object (created by calling createJDBCDataSource
on my factory above directly) to the embeddable EJB container?
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message