【问题标题】:IntelliJ IDEA cannot resolve spring imported filesIntelliJ IDEA 无法解析 spring 导入的文件
【发布时间】:2015-01-06 19:30:23
【问题描述】:

我有一个带有父 pom 文件和两个模块(名为“app”和“modules”)的多模块 maven 项目。在“app”的测试资源中,我有一个包含以下内容的弹簧配置:

<?xml version="1.0" encoding="UTF-8"?>
<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">

    <import resource="file:src/main/webapp/WEB-INF/spring-config/security.xml"/>
    <import resource="file:src/main/webapp/WEB-INF/spring-config/mvc-servlet.xml"/>
    <import resource="file:src/main/webapp/WEB-INF/spring-config/common.xml"/>

    <import resource="db-test.xml"/>
    <import resource="utilsContext.xml"/>
</beans>

IntelliJ IDEA 13 和 14 在我的情况下找不到作为资源导入的文件(security.xml、mvc-servlet.xml 和 common.xml),因此 IDEA 无法解析从 spring 上下文中注入对象。如果我将路径更改为 file:app/src/main/webapp/WEB-INF/spring-config/security.xml 那么一切正常,但它会使 maven 测试崩溃。

请告诉我如何配置 IntelliJ IDEA 的 spring 文件分辨率。

【问题讨论】:

  • 因为他们不应该...在运行时路径src/main/webapp 不存在,这仅在构建时可用。只需改用/WEB-INF/spring-config(没有file: 前缀)。如果您希望它们可用于测试,我建议将这些文件从WEB-INF 目录移到类路径上的某个位置,例如src/main/resources/META-INF。然后你可以做classpath:/META-INF/spring-config/security.xml等。
  • @M.Deinum 谢谢!我已将 spring-config 文件夹移至资源文件夹并使用了 classpath:/spring-config/security.xml refs。我所有的场景都有效!你能根据这个评论写一个答案吗?

标签: java spring maven intellij-idea


【解决方案1】:

在运行时路径src/main/webapp 不存在,这仅在构建时可用。只需使用/WEB-INF/spring-config(没有file: 前缀)代替。

如果您希望它们可用于测试,我建议将这些文件从 WEB-INF 目录移到类路径上的某个位置,例如 src/main/resources/META-INF。那你就可以classpath:/META-INF/spring-config/security.xml

【讨论】:

    猜你喜欢
    • 2014-10-24
    • 2017-02-27
    • 2016-09-02
    • 2011-09-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-29
    相关资源
    最近更新 更多