46

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,475
  • 28
  • 40
  • 37
Antoine
  • 1,433
  • 3
  • 17
  • 38
  • 1
    You didn't add the Spring .jar files to the classpath? – Andreas Jun 12 '16 at 12:33
  • 1
    Arf ! I didn't knew it wouldn't be done automatically .. I've searched and found how to do it thx to you :) – Antoine Jun 12 '16 at 12:44
  • "Cannot resolve symbol 'String'" - looks like your Java installation is broken or you have not configured the JDK in Intellij – OneCricketeer Jun 12 '16 at 17:06
  • Mmmhh it is kind of strange cause when i go into project structure the jdk 1.8 appear .. – Antoine Jun 12 '16 at 17:32
  • My JDK Wasn't configured as it should have been i've found how to do it properly here : http://stackoverflow.com/questions/4618794/intellj-idea-cannot-resolve-symbol-and-cannot-resolve-method – Antoine Jun 12 '16 at 17:58
  • After that i've decided to delete all and redo it again and it work like magic :) – Antoine Jun 12 '16 at 17:59
  • This question does not appear to be about programming within the scope defined in the help center. – Roman C Jun 13 '16 at 13:12
  • Your are missing some dependencies. Try this ! https://stackoverflow.com/questions/35293116/import-org-springframework-cannot-be-resolved – Mohamed Bouguerra Sep 26 '17 at 23:05

10 Answers10

49

enter image description here

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

Vinayak Shedgeri
  • 2,036
  • 20
  • 23
19

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
  • 255
  • 3
  • 9
4

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
2

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
  • 2,958
  • 7
  • 20
  • 35
1

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

Rahman786
  • 31
  • 6
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
  • 127
  • 9
0

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

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
  • 10,331
  • 15
  • 20
  • 47
0

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
  • 784
  • 1
  • 9
  • 19