0

我有以下代码行来加载应用程序上下文:

ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:META-INF/spring/spring-context.xml");

最初,我的项目是一个独立的 maven 项目,而且效果很好。我现在将项目分成两个模块,都共享一个父 pom.xml。到目前为止,我所有的测试都来自 Eclipse

父pom:

<groupId>parent</groupId>
<artifactId>parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>

<modules>
  <module>./config</module>
  <module>./ds</module>
</modules>

子项目 poms 的标题:

<parent>
   <artifactId>parent</artifactId>
   <groupId>parent</groupId>
   <version>0.0.1-SNAPSHOT</version>
   <relativePath>../pom.xml</relativePath>
</parent>

<modelVersion>4.0.0</modelVersion>
<groupId>ds</groupId>
<artifactId>ds</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>ds</name>

在父目录中只有父的 pom.xml,两个子项目在它下面。父 pom 的 maven 命令行构建工作正常。

现在,当加载应用程序上下文时(同样,从 Eclipse 运行),将引发以下错误:

Exception in thread "main" java.lang.ExceptionInInitializerError
at      org.springframework.context.support.AbstractRefreshableApplicationContext.createBeanFactory(AbstractRefreshableApplicationContext.java:195)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:128)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:527)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:441)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at com.bc.pog.ds.app.Main.main(Main.java:28)
Caused by: java.lang.NullPointerException
at org.springframework.beans.factory.support.DefaultListableBeanFactory.<clinit>(DefaultListableBeanFactory.java:109)
... 7 more

项目中没有 Spring jar 的冲突。有谁知道出了什么问题以及如何解决?非常感谢

4

0 回答 0