2013-07-22 20 views
1

我已經從另一位同事使用Eclipse創建的TSF中抽取了一個Java項目,但是,只要我在IntelliJ中打開該項目,就會得到以下運行時異常:'Spring.xml'從Eclipse遷移到IntelliJ的IOException異常問題

異常在線程 「主」 org.springframework.beans.factory.BeanDefinitionStoreException:從類路徑資源 IOException的解析XML文檔 [spring.xml];嵌套的例外是java.io.FileNotFoundException:類 路徑資源[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> 

任何建議和/或建議將不勝感激。提前致謝!

+1

spring.xml位於src/main/resources? –

+0

@ThorbjørnRavnAndersen,不是。我試圖創建目錄並將其放置在那裏,但它沒有解決問題。 – Carlos

回答

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"。您可以通過用false代替true並讓IntelliJ重新加載您的項目來快速測試。 我不知道爲什麼IntelliJ忽略你的spring.xml文件,但是如果你使用兩個單獨的目錄作爲源和資源,就像Maven建議的那樣,你的問題應該會消失。

您還應該創建目錄src/main/resources並將您的spring.xml文件放在那裏。

希望這會有所幫助。

+1

+1,謝謝你的回答。目前不工作,明天將嘗試您的建議,並希望將此問題標記爲已回答:) – Carlos

+0

,同時將'isMavenModule'更改爲'false'不能解決問題,您的建議會觸發一個結束解決問題的想法I正面臨着。我編輯了你的答案,包括我的解決方案,所以我可以把它作爲答案;) - 再次感謝! – Carlos

+0

感謝您的編輯。很高興答案幫助你:) –

0

有時這可能是工作目錄的問題。這blog post解釋了這個問題以及如何解決它。

的IntelliJ從Eclipse的不同之處在於它設置的工作目錄項目根這可能不一樣模塊您正在使用的頂級目錄。

通過將工作目錄設置爲$MODULE_DIR$,可以在運行配置中修復此問題。

如果這有幫助,可以在默認JUnit運行配置以及 中設置工作目錄,並修復所有剩餘的運行配置。