我从TSF中提取了一个Java项目,其他同事使用Eclipse创建,但是,每当我在IntelliJ中打开项目时,它都会遇到以下运行时异常:
线程“main”中的异常 org.springframework.beans.factory.BeanDefinitionStoreException: IOException从类路径资源解析XML文档 [spring.xml];嵌套异常是java.io.FileNotFoundException:class 路径资源[spring.xml]无法打开,因为它不存在 ... ......
我已经使用Maven下载所有项目依赖项似乎已经正常工作,因为我没有得到任何编译时异常。
我已将大部分项目配置设置上传到此imgur album,应该会有所帮助。
Main.java
ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");
Spring.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:p="http://www.springframework.org/schema/p"
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.2.3.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.3.xsd">
<bean id="ApplicationConfiguration" class="com.XXX.YYY.ZZZ.ApplicationConfiguration" />
<bean id="TableFactory" class="com.XXX.YYY.ZZZ.TableFactory">
<constructor-arg ref="ApplicationConfiguration" />
</bean>
<bean id="ItemFactory" class="com.XXX.YYY.ZZZ.datagen.ItemFactory"/>
<bean id="ItemWritersPool" class="com.XXX.YYY.ZZZ.ItemWritersPool">
<constructor-arg ref="ItemWriterFactory" />
<constructor-arg ref="ApplicationConfiguration" />
</bean>
<bean id="ItemWriterFactory" class="com.XXX.YYY.ZZZ.ItemWriterFactory">
<constructor-arg ref="ApplicationConfiguration" />
<constructor-arg ref="TableFactory" />
<constructor-arg ref="ItemFactory" />
</bean>
<bean id="ItemReadersPool" class="com.XXX.YYY.ZZZ.ItemReadersPool">
<constructor-arg ref="ItemReaderFactory" />
<constructor-arg ref="ApplicationConfiguration" />
</bean>
<bean id="ItemReaderFactory" class="com.XXX.YYY.ZZZ.ItemReaderFactory">
<constructor-arg ref="TableFactory" />
</bean>
</beans>
Project.iml
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="EclipseModuleManager">
<conelement value="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER" />
<src_description expected_position="0">
<src_folder value="file://$MODULE_DIR$/src" expected_position="0" />
</src_description>
</component>
<component name="FacetManager">
<facet type="Spring" name="Spring">
<configuration>
<fileset id="fileset" name="Spring Application Context" removed="false">
<file>file://$MODULE_DIR$/src/spring.xml</file>
<file>jar://$MAVEN_REPOSITORY$/io/netty/netty/3.6.3.Final/netty-3.6.3.Final.jar!/org/jboss/netty/container/spring/beans.xml</file>
<file>jar://$MAVEN_REPOSITORY$/org/springframework/spring-context/3.2.3.RELEASE/spring-context-3.2.3.RELEASE.jar!/org/springframework/scheduling/annotation/AbstractAsyncConfiguration.class</file>
<file>jar://$MAVEN_REPOSITORY$/org/springframework/spring-context/3.2.3.RELEASE/spring-context-3.2.3.RELEASE.jar!/org/springframework/cache/annotation/AbstractCachingConfiguration.class</file>
<file>jar://$MAVEN_REPOSITORY$/org/springframework/spring-context/3.2.3.RELEASE/spring-context-3.2.3.RELEASE.jar!/org/springframework/context/annotation/LoadTimeWeavingConfiguration.class</file>
<file>jar://$MAVEN_REPOSITORY$/org/springframework/spring-context/3.2.3.RELEASE/spring-context-3.2.3.RELEASE.jar!/org/springframework/context/annotation/MBeanExportConfiguration.class</file>
<file>jar://$MAVEN_REPOSITORY$/org/springframework/spring-context/3.2.3.RELEASE/spring-context-3.2.3.RELEASE.jar!/org/springframework/scheduling/annotation/ProxyAsyncConfiguration.class</file>
<file>jar://$MAVEN_REPOSITORY$/org/springframework/spring-context/3.2.3.RELEASE/spring-context-3.2.3.RELEASE.jar!/org/springframework/cache/annotation/ProxyCachingConfiguration.class</file>
<file>jar://$MAVEN_REPOSITORY$/org/springframework/spring-context/3.2.3.RELEASE/spring-context-3.2.3.RELEASE.jar!/org/springframework/scheduling/annotation/SchedulingConfiguration.class</file>
<file>file://$MAVEN_REPOSITORY$/org/springframework/spring-context/3.2.3.RELEASE/spring-context-3.2.3.RELEASE.jar</file>
</fileset>
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="inheritedJdk" />
[-- some items manually removed --]
<orderEntry type="library" name="Maven: org.springframework:spring-core:3.2.3.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-beans:3.2.3.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-context:3.2.3.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-aop:3.2.3.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-expression:3.2.3.RELEASE" level="project" />
[-- some items manually removed --]
</component>
</module>
任何建议和/或建议都将非常感谢。提前谢谢!
答案 0 :(得分:2)
您的配置中的所有内容都显示正常,因此我使用一个小项目进行了检查,看起来该问题可能来自您在XML标头中使用的冗余命名空间。
尝试修改以下内容:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
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.2.3.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.3.xsd">
导致类似这样的事情:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
如果这不起作用,您还可以通过执行以下操作来调整.iml
文件:
org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true"
。您可以通过将true
替换为false
来快速测试,并让IntelliJ重新加载您的项目。
我不知道为什么IntelliJ会忽略你的spring.xml
文件,但如果你使用2个独立的目录作为源和资源,正如Maven建议的那样,你的问题就会消失。
您还应创建目录src/main/resources
并将spring.xml
文件放在那里。
希望这有帮助。
答案 1 :(得分:0)
有时这可能是工作目录的问题。这个blog post解释了问题以及解决方法。
IntelliJ与Eclipse的不同之处在于它将工作目录设置为项目 root,这可能与您正在处理的模块的顶级目录不同。
通过将工作目录设置为$MODULE_DIR$
,可以在运行配置中修复此问题。
如果这有帮助,可以在Default JUnit运行配置中设置工作目录 并修复所有剩余的运行配置。