Vitalii Ivanov
Vitalii Ivanov

Reputation: 752

IntelliJ IDEA cannot resolve spring imported files

I have a multimodule maven project with parent pom file and two modules (named "app" and "modules"). In test resources of "app" I have a spring config with the following content:

<?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 and 14 cannot find files which are imported as resources in my case (security.xml, mvc-servlet.xml and common.xml) and so IDEA cannot resolve injection of objects from spring context. If I change path to file:app/src/main/webapp/WEB-INF/spring-config/security.xml then everything works fine, but it crashes maven tests.

Please, show me how to config IntelliJ IDEAs spring files resolutions.

Upvotes: 4

Views: 6923

Answers (1)

M. Deinum
M. Deinum

Reputation: 125232

At runtime the path src/main/webapp doesn't exists this is only available at build time. Just use /WEB-INF/spring-config (no file: prefix) instead.

If you want them to be available for tests I suggest moving those files out of the WEB-INF directory to somewhere on the classpath i.e. src/main/resources/META-INF for instance. Then you could do classpath:/META-INF/spring-config/security.xml

Upvotes: 5

Related Questions