58

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 written on the Jetbrains 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.

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...

How can I fix this?

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

But now I have got new errors I don't understand why... I should maybe download it directly and put the libraries 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 which isn't configured right since I don't have any completion anywhere and I can't create packages...

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Antoine Grenard
  • 1,712
  • 3
  • 21
  • 41

14 Answers14

60

enter image description here

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

Vinayak Shedgeri
  • 2,222
  • 1
  • 21
  • 24
22

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').

MrBlueSky
  • 305
  • 3
  • 10
7

Right click on the project and select Open In → Terminal

Context Menu

In the terminal, type → mvn -U idea:idea

terminal

It will resolve all the classpath issues for the particular project

Swapnil
  • 1,004
  • 1
  • 13
  • 21
6

Project root directory -> right click -> Add Framework Support --> Maven or Gradle --> Click Ok

Rahman786
  • 81
  • 1
  • 7
6

In my case triggering an Invalidate Caches/Restart helped IntelliJ now find those dependencies.

The Invalidate Caches/Restart option

Following what Mr. BlueSky told in his answer here, I could get the dependencies downloaded. Actually, the answer by Vinayak Shedgeri should have helped too. For those whom it didn't, you could try the invalidate cache/restart.

P. S.: And going by what could have caused this behavior, you could very well try something as simple as relaunching IntelliJ first. Just a guess.

Harshith Rai
  • 3,018
  • 7
  • 22
  • 35
5

Add dependency for springframework in pom.xml and run below command from directory where pom.xml exist.

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
  • Non-resolvable parent POM for the SNAPSHOT – KansaiRobot Nov 05 '19 at 01:59
  • I have faced the same issue as the OP. I had started the project from the scratch using IntelliJ IDE and spring initializer. The maven wasn't installed separately even though it was available as part of the project. I installed maven separately from this link https://maven.apache.org/download.cgi. Run the above command and it worked for me. – shanavascet Mar 10 '21 at 15:38
5

Please check if you have configured Maven Settings.

IntelliJ (File > Settings > Build,Execution,Deployment > Build Tools > Maven )

Maven home path : C:/Program Files/apache-maven-3.6.0

It resolved my error.

0

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

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

Aditya Goel
  • 201
  • 1
  • 15
0

Check if

/Users/<userName>/.m2/

location has settings.xml and toolchains.xml. I think toolchains might not be necessary but settings.xml is required. Instructions for creating settings.xml can be found here - https://maven.apache.org/settings.html

My issue was resolved after adding settigs.xml and toolchains.xml to above mentioned location and restarting the IDE.

jaySingh
  • 13
  • 3
0

Maven did not added dependencies on intellij so for this problem I restarted intellij IDE and when this time IDE stared it added dependencies successfully.

Peter Csala
  • 17,736
  • 16
  • 35
  • 75
0

import parent folder(Backend) instead of child folder(exam).

child folder(exam)

exam folder

parent folder(Backend)

Backend folder

0

I had a few spring-boot modules which were in perfect running state, but suddenly my PC went off and that created issues like: cannot resolve symbol 'springframework' and etc

[Maven -> Reload all maven projects] : this fixed the issue

blackgreen
  • 34,072
  • 23
  • 111
  • 129
shigal
  • 1
  • 2
0

What works for me was to close Intellij, erase the idea folder and open it again, Intellij seems to check everything again and then my dependency hasn't any issues

0

Just restart your IDE (Intellij) and it should ask you to start loading of the maven project. It worked for me.

  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 19 '23 at 07:39