2013-07-22 1 views
1

Я вытащил Java-проект из TSF, который другой коллега, созданный с использованием Eclipse, однако, всякий раз, когда я открываю проект в IntelliJ, он получает следующее исключение во время выполнения:«Spring.xml» Проблемы с IOException с перенесенным проектом из Eclipse в IntelliJ

Исключение в потоке "главный" 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". Вы можете быстро протестировать, заменив true на false и позвольте IntelliJ перезагрузить ваш проект. Я не знаю, почему IntelliJ игнорирует ваш файл spring.xml, но если вы используете 2 отдельных каталога для источников и ресурсов, как предполагает Maven, ваша проблема должна исчезнуть.

Вы также должны создать каталог src/main/resources и разместить там свой файл spring.xml.

Надеюсь, это поможет.

+1

+1, Спасибо за ответ. На данный момент не работает, попробуем ваше предложение завтра и, надеюсь, отметьте этот вопрос как ответ: – Carlos

+0

при изменении 'isMavenModule' на' false' не разрешил проблему, ваше предложение вызвало идею, которая в конечном итоге решила проблему I был лицом к лицу. Я отредактировал ваш ответ, чтобы включить мое решение, чтобы я мог сделать это как ответ;) - Еще раз спасибо! – Carlos

+0

Спасибо за редактирование. Рад, что ответ помог вам :) –

0

Иногда это может быть проблемой для рабочего каталога. Это blog post объясняет проблему и как ее исправить.

IntelliJ отличается от Eclipse, в том, что он устанавливает рабочий каталог проекта корня, который не может быть таким же, как каталог верхнего уровня модуля вы работаете.

Это можно зафиксировать в конфигурациях запуска, установив рабочий каталог на $MODULE_DIR$.

Если это помогает, возможно, установить рабочий каталог в конфигурации запуска по умолчанию JUnit, а также и исправить все оставшиеся конфигурации запуска.

 Смежные вопросы

  • Нет связанных вопросов^_^