gpt4 book ai didi

java - jdo/OSGi : error building JDO PersistenceManagerFactory after bundle update

转载 作者:行者123 更新时间:2023-12-02 06:37:02 26 4
gpt4 key购买 nike

我在 karaf 2.2.10 之上使用带有 datanucleus-mongodb 3.2.3 和 spring 3.0.7 的 JDO。

在新的 OSGi bundle 安装中,我能够在 mongodb 上持久保存而不会出现问题,但是在重新安装 bundle 后,我在构建新的 JDO PersistenceManagerFactory 时收到以下错误:

ERROR: Bundle [my_bundle] [242] Unable to get module class path.
(java.lang.IllegalStateException: zip file closed)

其中 ID (242) 指的是第一个分配给 bundle 的 ID(换句话说,旧 bundle 的 ID)。

上一个包的上下文以及“旧”JDO PersistenceManagerFactory 似乎已正确关闭。

我的本​​地持久化管理器工厂 bean 类(基于 example provided in the dn site ):

public class OSGiLocalPersistenceManagerFactoryBean
extends LocalPersistenceManagerFactoryBean implements BundleContextAware {

public static final String JDO_BUNDLE_NAME = "org.datanucleus.api.jdo";
public static final String JDO_PMF_CLASS_NAME = "org.datanucleus.api.jdo.JDOPersistenceManagerFactory";

private BundleContext bundleContext;

@Override
protected PersistenceManagerFactory newPersistenceManagerFactory(String name) {
return JDOHelper.getPersistenceManagerFactory(name, getClassLoader());
}

@Override
protected PersistenceManagerFactory newPersistenceManagerFactory(Map props) {
ClassLoader classLoader = getClassLoader();

props.put("datanucleus.primaryClassLoader", classLoader);

if (FrameworkUtil.getBundle(this.getClass()) != null) { // running in OSGi
props.put("datanucleus.plugin.pluginRegistryClassName", "org.datanucleus.plugin.OSGiPluginRegistry");
}

PersistenceManagerFactory pmf = JDOHelper.getPersistenceManagerFactory(props, classLoader);

return pmf;
}

private ClassLoader getClassLoader() {
ClassLoader classLoader = null;
Bundle thisBundle = FrameworkUtil.getBundle(this.getClass());

if (thisBundle != null) { // on OSGi runtime
Bundle[] bundles = bundleContext.getBundles();

for (Bundle bundle : bundles) {
if (JDO_BUNDLE_NAME.equals(bundle.getSymbolicName())) {
try {
classLoader = bundle.loadClass(JDO_PMF_CLASS_NAME).getClassLoader();
} catch (ClassNotFoundException e) {
// do something fancy here ...
}
break;
}
}
} else { // somewhere else
classLoader = this.getClass().getClassLoader();
}
return classLoader;
}

@Override
public void setBundleContext(BundleContext bundleContext) {
this.bundleContext = bundleContext;
}
}

上下文中一些与持久性相关的摘录:

<!-- persistence manager factory -->
<bean id="pmf" class="[my_package].OSGiLocalPersistenceManagerFactoryBean">
<property name="configLocation" value="classpath:datanucleus.properties" />
</bean>

<!-- persistence manager factory proxy -->
<bean id="persistenceManagerFactoryProxy"
class="org.springframework.orm.jdo.TransactionAwarePersistenceManagerFactoryProxy">
<property name="targetPersistenceManagerFactory" ref="pmf" />
</bean>

<!-- transactions -->
<bean id="transactionManager" class="org.springframework.orm.jdo.JdoTransactionManager">
<property name="persistenceManagerFactory" ref="persistenceManagerFactoryProxy" />
</bean>

<tx:annotation-driven />

错误消息似乎指向类加载问题,但是为什么它只在重新部署期间失败?

任何提示将不胜感激!

最佳答案

确保您还刷新了依赖的 bundle ,因为这些 bundle 通常会保留在旧的已卸载的 bundle 中。它仍然存在,直到清除所有引用为止。在 Karaf shell 中,您只需要发出刷新或简单刷新而不需要 ID,这将导致整个容器重新布线:)

关于java - jdo/OSGi : error building JDO PersistenceManagerFactory after bundle update,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19524534/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com