Java Intellij:无法解析符号“springframework”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37774282/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 19:39:38  来源:igfitidea点击:

Intellij : Cannot resolve symbol 'springframework'

javaspringintellij-idea

提问by Antoine

I'm trying to start my first project with Spring. I use intellij idea and i'm kind of new to it too. But anyways, i followed the step wrote on the jetbrain website and i don't know what i have done wrong but i got a lot of errors on the first to files that are created by default.

我正在尝试用 Spring 开始我的第一个项目。我使用 Intellij 的想法,我对它也很陌生。但无论如何,我按照在 jetbrain 网站上写的步骤进行操作,我不知道我做错了什么,但是我在第一个默认创建的文件中遇到了很多错误。

BloomBookingApplcation.java

BloomBookingApplcation.java

package com.bloombooking;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class BloomBookingApplication {

    public static void main(String[] args) {
        SpringApplication.run(BloomBookingApplication.class, args);
    }
}

Error:(3, 12) Cannot resolve symbol 'springframework'
Error:(4, 12) Cannot resolve symbol 'springframework'
Error:(6, 2) Cannot resolve symbol 'SpringBootApplication'
Warning:(7, 1) Access can be packageLocal
Error:(9, 26) Cannot resolve symbol 'String'
Error:(10, 3) Cannot resolve symbol 'SpringApplication'

Maybe i'm stupid but i don't know which step i've missed ...

也许我很笨,但我不知道我错过了哪一步......

Can someone help me ?

有人能帮我吗 ?

I have found the way to add spring with the quickfix button.

我找到了使用 quickfix 按钮添加弹簧的方法。

But now i have got new errors i don't understand why ... I should maybe download it directly and put the librairies one by one maybe ?

但是现在我有了新的错误,我不明白为什么......我也许应该直接下载它并一个一个地放置图书馆?

Error:(3, 28) Cannot resolve symbol 'boot'
Error:(4, 28) Cannot resolve symbol 'boot'
Error:(6, 2) Cannot resolve symbol 'SpringBootApplication'
Warning:(7, 1) Access can be packageLocal
Error:(9, 26) Cannot resolve symbol 'String'
Error:(10, 3) Cannot resolve symbol 'SpringApplication'

Or maybe it's my intellij idea wich isn't configured right since i don't have any completion anywhere and i can't create packages ...

或者也许是我的智能想法没有正确配置,因为我在任何地方都没有任何完成并且我无法创建包......

回答by Peter Sz.

I would recommend using the Spring Initializrpage to do basic/first project setup. It takes care of all the spring boot dependencies.

我建议使用Spring Initializr页面进行基本/第一个项目设置。它负责处理所有 Spring Boot 依赖项。

Once downloaded/unpacked the zip file, you can use the File -> New -> Project From Existing Sources... option in IntelliJ do import it.

下载/解压 zip 文件后,您可以使用 IntelliJ 中的 File -> New -> Project From Existing Sources... 选项导入它。

回答by MrBlueSky

I had the same problem, and this is how it worked for me:

我遇到了同样的问题,这对我来说是这样的:

On the source root directory -> right click -> Add Framework Support.

在源码根目录->右键->添加框架支持。

A window will open with different categories, such as Java EE, JBoss etc. Go to 'Spring' category. Then, download the pack of libraries that you need (I used 'Spring MVC').

将打开一个包含不同类别的窗口,例如 Java EE、JBoss 等。转到“Spring”类别。然后,下载您需要的库包(我使用了“Spring MVC”)。

回答by Vinayak Shedgeri

enter image description here

在此处输入图片说明

Click on refresh button .Maven may not be able to sync properly

单击刷新按钮。Maven 可能无法正确同步

回答by SaravanaKumar KKB

Add dependency for springframework in pom.xmland run below command from directory where pom.xmlexist.

为 springframework 添加依赖项,pom.xml并从pom.xml存在的目录中运行以下命令。

mvn clean install -U

Above command will forcefully download the dependencies.

以上命令将强制下载依赖项。

if you are behind proxy then try below command

如果您在代理后面,请尝试以下命令

mvn clean install -DproxySet=true -DproxyHost=www-proxy.us.com -DproxyPort=80

回答by Aditya Goel

In my case, I was behind Office proxy and that why MAVEN was unable to download the required dependencies on its own !

就我而言,我支持 Office 代理,这就是为什么 MAVEN 无法自行下载所需的依赖项!

After switching the network and executing below command : mvn clean install -U, it worked !!

切换网络并执行以下命令后:mvn clean install -U,它工作了!!