OSGI软件包的类路径通常是META-INF文件夹。 “spring-context.xml”文件位于META-INF下的spring文件夹中。你可以在应用程序图片中看到。这个XML文件没有被ClassPathXmlApplicationContext找到。在我看来问题是Classpath。但我没有解决这个问题。在我的应用程序中,我尝试使用spring-dm配置hibernate。在构建应用程序时,我帮助了这个website。启动OSGI应用程序时未找到context.xml
我下面分享给HİbernateUtil.class:
public abstract class HibernateUtil {
private SessionFactory sessionFactory;
private SessionFactory buildSessionFactory() {
try {
if (this.sessionFactory == null) {
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("META-INF/spring/spring-context.xml");
this.sessionFactory = (SessionFactory) applicationContext.getBean("sessionFactory");
}
} catch (Throwable ex) {
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
return this.sessionFactory;
}
public Session newSession() {
if (this.sessionFactory == null)
buildSessionFactory();
return (this.sessionFactory == null ? null : this.sessionFactory.openSession());
}
}
我同意下列弹-context.xml中:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
\t xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:osgi="http://www.springframework.org/schema/osgi"
\t xmlns:context="http://www.springframework.org/schema/context"
\t xsi:schemaLocation="http://www.springframework.org/schema/beans
\t \t \t http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/osgi
\t \t \t \t http://www.springframework.org/schema/osgi/spring-osgi.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd">
\t <context:annotation-config />
\t <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
\t \t init-method="createDataSource"
\t \t destroy-method="close">
\t \t <property name="driverClassName" value="org.postgresql.Driver" />
\t \t <property name="url" value="jdbc:postgresql://127.0.0.1:5432/xxxxx" />
\t \t <property name="username" value="xxxxx" />
\t \t <property name="password" value="xxxxx" />
\t \t <property name="maxActive" value="100" />
\t \t <property name="maxIdle" value="50" />
\t \t <property name="maxWait" value="1000" />
\t </bean>
\t <bean id="sessionFactory"
\t \t class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
\t \t <property name="dataSource" ref="dataSource" />
\t \t <property name="annotatedClasses">
\t \t \t <list>
\t \t \t \t <value>tr.cc.ex.dict.kernel.model.xxxx</value>
\t \t \t \t <value>tr.cc.ex.dict.kernel.model.xxxx</value>
\t \t \t \t <value>tr.cc.ex.dict.kernel.model.xxxx</value>
\t \t \t \t <value>tr.cc.ex.dict.kernel.model.xxxx</value>
\t \t \t \t <value>tr.cc.ex.dict.kernel.model.xxxx</value>
\t \t \t \t <value>tr.cc.ex.dict.kernel.model.xxxx</value>
\t \t \t \t <value>tr.cc.ex.dict.kernel.model.xxxx</value>
\t \t \t \t <value>tr.cc.ex.dict.kernel.model.xxxx</value>
\t \t \t \t
\t \t \t </list>
\t \t </property>
\t \t <property name="hibernateProperties">
\t \t \t <props>
\t \t \t \t <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
\t \t \t \t <prop key="hibernate.show_sql">false</prop>
\t \t \t \t <prop key="hibernate.format_sql">false</prop>
\t \t \t </props>
\t \t </property>
\t </bean>
\t
</beans>
我同意下列体现-MF:
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Model
Bundle-SymbolicName: tr.cc.ex.dict.kernel.model;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: tr.cc.ex.dict.kernel.model.internals.Activator
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
Bundle-ClassPath: .
Export-Package: tr.cc.ex.dict.kernel.model,
tr.cc.ex.dict.kernel.model.hibernate.util
Import-Package: javax.persistence;version="1.99.0",
org.apache.commons.dbcp;version="1.4.0",
org.hibernate;version="3.4.0.GA-A",
org.hibernate.cfg;version="3.3.2.GA",
org.hibernate.ejb;version="3.4.0.GA-A",
org.osgi.framework;version="1.8.0",
org.postgresql;version="9.4.0",
org.springframework.beans;version="3.1.0.RELEASE",
org.springframework.beans.factory;version="3.1.0.RELEASE",
org.springframework.beans.factory.config;version="3.1.0.RELEASE",
org.springframework.context;version="3.1.0.RELEASE",
org.springframework.context.support;version="3.1.0.RELEASE",
org.springframework.core.io.support;version="3.1.0.RELEASE",
org.springframework.orm.hibernate3;version="3.1.0.RELEASE",
org.springframework.orm.hibernate3.annotation;version="3.1.0.RELEASE",
tr.cc.ex.dict.sys.comp
这张照片是app文件夹:
我分享给应用程序控制台输出如下:
Nis 13, 2017 7:13:59 AM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org[email protected]5ca1b42c: startup date [Thu Apr 13 07:13:59 EET 2017]; root of context hierarchy
Nis 13, 2017 7:13:59 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [META-INF/spring/spring-context.xml]
Initial SessionFactory creation failed.org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [META-INF/spring/spring-context.xml]; nested exception is java.io.FileNotFoundException: class path resource [META-INF/spring/spring-context.xml] cannot be opened because it does not exist
gogo: InvocationTargetException: null
你的build.properties包含什么? –
source .. = src/ output .. = bin/ bin.includes =。,\ META-INF/ –