簡體   English   中英

啟動OSGI應用程序時找不到context.xml

[英]context.xml not found when starting OSGI application

OSGI bundles的類路徑通常是META-INF文件夾。 “ spring-context.xml”文件位於META-INF下的spring文件夾中。 您可以在應用程序圖片中看到。 ClassPathXmlApplicationContext找不到此xml文件。 我認為問題是類路徑。 但是我沒有解決這個問題。 在我的應用程序中,我嘗試使用spring-dm配置休眠模式。 在構建應用程序時,我幫助了該網站

我在下面分享給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());
    }

}

我與spring-context.xml分享以下內容:

 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:osgi="http://www.springframework.org/schema/osgi" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/osgi 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"> <context:annotation-config /> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" init-method="createDataSource" destroy-method="close"> <property name="driverClassName" value="org.postgresql.Driver" /> <property name="url" value="jdbc:postgresql://127.0.0.1:5432/xxxxx" /> <property name="username" value="xxxxx" /> <property name="password" value="xxxxx" /> <property name="maxActive" value="100" /> <property name="maxIdle" value="50" /> <property name="maxWait" value="1000" /> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="annotatedClasses"> <list> <value>tr.cc.ex.dict.kernel.model.xxxx</value> <value>tr.cc.ex.dict.kernel.model.xxxx</value> <value>tr.cc.ex.dict.kernel.model.xxxx</value> <value>tr.cc.ex.dict.kernel.model.xxxx</value> <value>tr.cc.ex.dict.kernel.model.xxxx</value> <value>tr.cc.ex.dict.kernel.model.xxxx</value> <value>tr.cc.ex.dict.kernel.model.xxxx</value> <value>tr.cc.ex.dict.kernel.model.xxxx</value> </list> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop> <prop key="hibernate.show_sql">false</prop> <prop key="hibernate.format_sql">false</prop> </props> </property> </bean> </beans> 

我與MANIFEST-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

此圖片是應用程序文件夾:

在此處輸入圖片說明

我在下面分享到應用程序控制台輸出:

Nis 13, 2017 7:13:59 AM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@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中包含目錄META-INF。 據我所知,這意味着該jar內的路徑沒有META-INF部分。 您可以嘗試“ spring / spring-context.xml”嗎?

我更改了ApplicationContext行下面的代碼,可能我解決了這個問題。 但是應用程序並非沒有問題就開始:

ApplicationContext applicationContext = new FileSystemXmlApplicationContext("/Desktop/dictionary_project/tr.cc.ex.dict.kernel.model/META-INF/spring/spring-context.xml");

我共享新的控制台輸出:

Nis 13, 2017 2:19:03 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.FileSystemXmlApplicationContext@5e474f1b: startup date [Thu Apr 13 14:19:03 EET 2017]; root of context hierarchy
Nis 13, 2017 2:19:03 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from file [/home/oem/Desktop/dictionary_project/tr.cc.ex.dict.kernel.model/META-INF/spring/spring-context.xml]
Initial SessionFactory creation failed.org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/context]
Offending resource: file [/home/oem/Desktop/dictionary_project/tr.cc.ex.dict.kernel.model/META-INF/spring/spring-context.xml]

然后,我搜索此異常。 應用程序具有“ org.springframework.context”捆綁包。 但是我不明白為什么應用會拋出這個異常。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM