Java 启动OSGI应用程序时未找到context.xml

Java 启动OSGI应用程序时未找到context.xml,java,spring,hibernate,osgi,Java,Spring,Hibernate,Osgi,OSGI捆绑包的类路径通常是META-INF文件夹。“spring context.xml”文件位于META-INF下的spring文件夹中。您可以在应用程序图片中看到。ClassPathXmlApplicationContext找不到此xml文件。在我看来,问题在于类路径。但我没有解决这个问题。在我的应用程序中,我尝试使用SpringDM配置hibernate。我在构建应用程序时帮助了这一点 我将以下内容分享给HİbernateUtil.class: public abstract class

OSGI捆绑包的类路径通常是META-INF文件夹。“spring context.xml”文件位于META-INF下的spring文件夹中。您可以在应用程序图片中看到。ClassPathXmlApplicationContext找不到此xml文件。在我看来,问题在于类路径。但我没有解决这个问题。在我的应用程序中,我尝试使用SpringDM配置hibernate。我在构建应用程序时帮助了这一点

我将以下内容分享给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共享以下内容:


tr.cc.ex.dict.kernel.model.xxxx
tr.cc.ex.dict.kernel.model.xxxx
tr.cc.ex.dict.kernel.model.xxxx
tr.cc.ex.dict.kernel.model.xxxx
tr.cc.ex.dict.kernel.model.xxxx
tr.cc.ex.dict.kernel.model.xxxx
tr.cc.ex.dict.kernel.model.xxxx
tr.cc.ex.dict.kernel.model.xxxx
org.hibernate.dialogue.PostgreSqlDialogue
假的
假的

在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”包。但我不明白为什么应用程序会抛出这个异常

build.properties包含哪些内容?source..=src/output..=bin/bin.includes=,\META-INF/