试图在Karaf中运行Hibernate

时间:2018-06-07 08:50:23

标签: osgi noclassdeffounderror apache-karaf

我创建了一个在Karaf(OSGi)上运行的简单示例组件。我用main()方法测试了代码并且它可以工作。我把它放入卡拉夫之后。卡拉夫抛出错误,表示激活器出错。

  

2018-06-07T16:40:53,529 |错误| fileinstall -D:\ apache-karaf-4.2.0 / deploy | scr | 51 - org.apache.felix.scr - 2.0.14 | [com.umedia.database.internal.RepoServiceImpl(7)] activate方法抛出异常   java.lang.NoClassDefFoundError:无法初始化类org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl       在org.hibernate.boot.registry.BootstrapServiceRegistryBuilder.build(BootstrapServiceRegistryBuilder.java:218)〜[?:?]       在org.hibernate.boot.registry.StandardServiceRegistryBuilder。(StandardServiceRegistryBuilder.java:58)〜[?:?]       在com.umedia.database.internal.RepoServiceImpl.activate(RepoServiceImpl.java:49)〜[?:?]

我尝试跟踪Hibernate源代码,看起来就像BootstrapServiceRegistryBuilder.java

中的这一行
classLoaderService = new ClassLoaderServiceImpl( classLoaders,tcclLookupPrecedence );

我的激活码

StandardServiceRegistryBuilder registryBuilder = new StandardServiceRegistryBuilder();
Map<String, String> settings = new HashMap<>();
settings.put(Environment.DRIVER, "org.postgresql.Driver");
settings.put(Environment.URL, "jdbc:postgresql://127.0.0.1:5432/osgi");
settings.put(Environment.USER, "******");
settings.put(Environment.PASS, "******");
settings.put(Environment.DIALECT, "org.hibernate.dialect.PostgreSQL95Dialect");         

// Apply settings
registryBuilder.applySettings(settings);
// Create registry
registry = registryBuilder.build();
// Create MetadataSources
MetadataSources sources = new MetadataSources(registry);
// Create Metadata
Metadata metadata = sources.getMetadataBuilder().build();
// Create SessionFactory
sessionFactory = metadata.getSessionFactoryBuilder().build();

我的maven依赖包括:

postgresql 9.4.1212,hibernate-core 5.2.16和hibernate-osgi 5.2.12

那么,我怎么知道类加载器试图加载什么?

编辑1: 运行feature:install hibernate=orm并在Karaf上安装hibernate 5.2之后。 错误消息显示:

  

引起:java.lang.ClassNotFoundException:数据库找不到org.hibernate.service.ServiceRegistry [44]

0 个答案:

没有答案