How to avoid boot problems in MyBatis under OSGI?

I am working on an Eclipse 3.7 RCP application with multiple modules. Module A is a collection of libraries, including mybatis-3.2.2.jar. Module B depends on module A (Require-Bundle in the .mf manifest) and has code that uses MyBatis to access data in the database. I exported packages with the mapper and XML classes to module B and imported them into module A. I create SqlSessionFactory in the code and it works fine if I add all the Mapper classes by name, for example.

configuration.addMapper(MyMapper.class);

however, when I try to add all the mappers to the package:

configuration.addMappers(MyMapper.class.getPackage().getName());

MyBatis does not see them.

I tried changing the default class loader, but that didn't help.

Resources.setDefaultClassLoader(this.getClass().getClassLoader());

I suspect the problem is with class visibility in OSGI. If so, are there any ways to fix it in the application?

+4
3

Spring Data JPA Felix OSGi. factory :

ClassLoader pre = Thread.currentThread().getContextClassLoader();
try {
    Thread.currentThread().setContextClassLoader(context.getClassLoader());
    // add mappers here or call super method
} finally {
    Thread.currentThread().setContextClassLoader(pre);
}

Spring, B BundleWiring.

Bundle bundle; //get this by symbolic name if you don't have a reference
BundleWiring bundleWiring = bundle.adapt(BundleWiring.class);
bundleWiring.getClassLoader();

, addMappers A . , , MapperRegistry.

+2

Resources.setDefaultClassLoader(Activator.class.getClassLoader()). , OSGi . , .

+2

All Articles