java - 导入 spring xml 文件时出现 FileNotFoundException

标签 java xml spring

我的 xml 文件之一中有以下行,以包含位于我的 Maven 项目的 src/main/resources/configspring.xml 文件。

<import resource="classpath:config/spring.xml"/> 

我的构建路径中有位置src/main/resources。尽管如此,在运行它时。它给出了以下异常

Caused by: java.io.FileNotFoundException: class path resource [spring.xml] cannot be opened because it does not exist
at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:158)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:329)
... 13 more

下面是构建路径源选项卡

enter image description here

src/main/resources/:

enter image description here

编辑: 由于某种原因,我的目标文件夹也没有类文件夹

enter image description here

编辑:全新安装后,我在目标文件夹中得到以下文件夹:

enter image description here

编辑:pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.springframework.samples</groupId>
    <artifactId>SpringHibernateExample</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <properties>

        <!-- Generic properties -->
        <java.version>1.6</java.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

        <!-- Spring -->
        <spring-framework.version>4.0.3.RELEASE</spring-framework.version>

        <!-- Hibernate / JPA -->
        <!-- <hibernate.version>4.3.5.Final</hibernate.version> -->
        <hibernate.version>3.6.9.Final</hibernate.version>

        <!-- Logging -->
        <logback.version>1.0.13</logback.version>
        <slf4j.version>1.7.5</slf4j.version>

    </properties>

    <dependencies>
        <!-- Spring and Transactions -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${spring-framework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>${spring-framework.version}</version>
        </dependency>

        <!-- Spring ORM support -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>${spring-framework.version}</version>
        </dependency>

        <!-- Logging with SLF4J & LogBack -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>${slf4j.version}</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>${logback.version}</version>
            <scope>runtime</scope>
        </dependency>

        <!-- Hibernate -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>${hibernate.version}</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>${hibernate.version}</version>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.9</version>
        </dependency>
        <dependency>
            <groupId>commons-dbcp</groupId>
            <artifactId>commons-dbcp</artifactId>
            <version>1.4</version>
        </dependency>
    </dependencies>
</project>

classes 文件夹存在于导入项目所在的位置,但在 eclipse 项目结构中不可见

enter image description here

最佳答案

尝试将/放在config之前。像这样:

classpath:/config/spring.xml

编辑:将资源路径的排除设置为(无)包含:(全部)

关于java - 导入 spring xml 文件时出现 FileNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52353224/

相关文章:

Java 堆内存使用波动

java - 从后台堆栈中删除特定 fragment

java - Flex 文件下载

javascript - 在当前/新窗口中显示 xml

eclipse - 图类型提供者不能为空

java - 如何在SWT中选择用于保存的文件夹?

xml - XSD 正则表达式 : Why is this not working when parsed into HTML with an XSLT?

java - 适用于 Android 的 BBC iPlayer 广播应用程序 - 滚轮导航

java - 模拟Mvc。如何在junit测试中涉及自定义对象

spring - 在tomcat上部署应用程序时找不到文件