【问题标题】:Import org.springframework in a maven project在 maven 项目中导入 org.springframework
【发布时间】:2017-01-09 15:04:23
【问题描述】:

我在 Maven 环境中学习 Spring。我正在使用 netbeans。

pom.xml

<dependencies>
    <?xml version="1.0" encoding="UTF-8"?>
<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>com.davidsalter.cookbook</groupId>
<artifactId>springMavenTest</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
</properties>

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

</project>

并且 spring.context-4.3.4.RELEASE.jar 出现在 Dependencies 下。在 Java Dependencies 下我只有 JDK1.8。

当我必须使用@Configuration 和@Bean 注释在java 类中配置我的bean 时,我无法导入org.springframework

【问题讨论】:

    标签: java spring maven netbeans


    【解决方案1】:

    看来您只是在 NetBeans 中创建了一个 maven 项目。您在pom.xml 中声明的maven 依赖项将被下载并列在Dependencies 文件夹中。

    右键单击Dependencies 文件夹并单击Download Declared Dependencies 以重新加载依赖项。如果仍然失败,您可能需要在 setting.xml 中检查您的 maven 代理。

    【讨论】:

      【解决方案2】:

      更新您的项目。 通过执行 Alt + F5 然后选择您的项目,然后单击确定

      否则右键单击您的项目 -> Maven -> 更新项目。 确保您已连接到 Internet 以下载所有这些 spring 依赖项。

      【讨论】:

      • 我正在使用 netbeans,如果我从项目窗口右键单击我的 maven 项目,我没有任何“Maven”选项。如果我选择“使用依赖项构建”,则此 link 有错误。我在帖子中添加了完整的 pom
      猜你喜欢
      • 2011-09-17
      • 2013-11-22
      • 1970-01-01
      • 2014-01-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-07
      相关资源
      最近更新 更多