import org.springframework 无法解析

huangapple go评论78阅读模式
英文:

import org.springframework cannot be resolved in

问题

这是我的pom.xml文件。我正在使用Eclipse。我尝试创建一个Hello World Spring应用程序。

<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>spring-boot-gradle</groupId>
  <artifactId>spring-boot-gradle</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.0</version>
        <configuration>
          <release>13</release>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>
英文:

Here is my pom.xml file.I am using eclipse .I am trying to make a helloworld spring application .T
https://www.tutorialspoint.com/spring/spring_hello_world_example.htm

&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
  &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  &lt;groupId&gt;spring-boot-gradle&lt;/groupId&gt;
  &lt;artifactId&gt;spring-boot-gradle&lt;/artifactId&gt;
  &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
  &lt;build&gt;
    &lt;plugins&gt;
      &lt;plugin&gt;
        &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
        &lt;version&gt;3.8.0&lt;/version&gt;
        &lt;configuration&gt;
          &lt;release&gt;13&lt;/release&gt;
        &lt;/configuration&gt;
      &lt;/plugin&gt;
    &lt;/plugins&gt;
  &lt;/build&gt;
&lt;/project&gt;

答案1

得分: 1

你需要在 pom.xml 文件中声明你的 Maven 项目的依赖关系。一旦你更新了 Maven 项目(右键单击项目,然后在 maven 选项中选择更新项目),这些 JAR 包将由你的项目进行管理,之后你才能够导入 Spring 特定的类。你可以像下面这样在 pom.xml 中声明依赖关系:

<dependencies>
  <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    <version>5.2.4.RELEASE</version>
  </dependency>
</dependencies>

如果你对 Maven 基础不够清楚,你可以在任何入门教程中了解更多关于 Maven 依赖的内容。

英文:

You need to declare dependencies to your maven project inside pom.xml. Once you update your maven project ( right click project and inside maven option update project). Those jars will be managed by your project and after that only you will be able to import spring specific classes. You can declare dependencies in pom.xml like below:

&lt;dependencies&gt;
  &lt;dependency&gt;
    &lt;groupId&gt;org.springframework&lt;/groupId&gt;
    &lt;artifactId&gt;spring-web&lt;/artifactId&gt;
    &lt;version&gt;5.2.4.RELEASE&lt;/version&gt;
  &lt;/dependency&gt;
&lt;/dependencies&gt;

You can read more about maven dependencies in any beginner tutorial in case you are not clear about maven basics.

huangapple
  • 本文由 发表于 2020年3月15日 21:31:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/60693449.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定