6

即使我将 jar 依赖项添加到 pom.xml 中,IntelliJ 也无法在 Maven 模块中找到类。

我创建了一个 Maven 模块: test-intellij 。然后我创建了一个类TestApp并使其实现ApplicationContextAware如下:

public class TestApp implements  ApplicationContextAware{
}

IntelliJ 告诉我:“找不到类 ApplicationContextAware”。所以我按下“alt + enter”,然后从弹出提示中选择“添加 maven 依赖项”。

经过这个操作,pom.xml中添加了下面的依赖成功:

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>3.1.3.RELEASE</version>
    </dependency>

但是当我尝试导入 ApplicationContextAware 类时,IntelliJ 仍然找不到要导入的 ApplicationContextAware 类。

有人可以帮我解决这个问题吗?

4

1 回答 1

9

Try to Reimport the Maven project using the corresponding button in IntelliJ IDEA Maven Projects tool window. Wait until the dependency is downloaded and indexing is complete. File | Invalidate Caches may also help.

Also check that you are using the latest IDEA version (12.0.2 at the moment). You should be able to browse inside the downloaded dependency jar in the Project View, External Libraries node.

于 2013-01-22T07:59:57.797 回答