Difficulty Getting Spring Boot Project Working

Answered

Hi all.  I just got a 1 year license and have read articles, watched tutorials, tried everything I can and I'm having the hardest time getting the simplest Spring Boot app working in IntelliJ IDEA.

I have several Spring Boot projects in NetBeans and would like to be able to work on them.  If I do a new project with existing sources, it doesn't honor my Maven project structure and tries to add every /src/main folder in each Maven module as a source.  It never recognizes Spring as a framework or as a Facet.  I can manually add Spring as a facet, but it doesn't seem to affect anything.  Almost every class I have shows that every import is unused, and the code itself that uses the imported classes, the IDE says it can't locate that class.  

I gave up and tried doing a new, simple project using the Spring Initializr.  The only dependency I add is web and create my new project.  It seems to build the project fine, but it doesn't seem to recognize it as a runnable project.  If I go into Run/Debug Configurations, select Spring Boot, then try to type in my main class (com.example.DemoApplication), "example" shows up red and it says it can't resolve symbol.  The class with the main method does not have a green arrow.

Here is my build info:

IntelliJ IDEA 2016.2.1
Build #IU-162.1447.26, built on August 2, 2016
JRE: 1.8.0_76-release-b216 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o

For the life of me I can't figure out what I'm doing wrong.  Any help would be appreciated.

1
26 comments

Did you try this guide: https://www.jetbrains.com/help/idea/2016.2/creating-spring-boot-projects.html ?

There is an option to create run/debug configuration automatically.

Also, in the class with the main method you can just right click and run it, IDEA will create Application Run/Debug configuration automatically (and you can save it later to make persistent).

0

That is one of the guides I followed and I just stepped through it again.  Extremely simple -- just follow the menus.  But the result is the same.  None of the dialogs form right-clicking on the project, the class, or inside the editor window give me an option to run.  The run icon in the top right corner is grayed out.  

If I click on Run on the menu bar and then run again, it brings up a run window that has one option to Edit configurations.  They are blank so I choose Spring Boot, then go to type in my main class (com.example) and just like before, it can't find example.

I feel like something has to be messed up somewhere.  Shouldn't this just work?

1

The project source roots are not configured. Try importing the project from pom.xml instead and check idea.log for errors (https://intellij-support.jetbrains.com/hc/articles/207241085). Once the project is properly imported from Maven, src/main/java will be marked as the source root (blue color).

If you already see this project in the Maven Projects tool window, try to Refresh it.

There could be some Maven specific issue that prevents it from importing (like older Maven version or incorrect memory setting leading to Maven importer process crash).

0

Thanks Serge.  Although it still doesn't seem right that I would have to create a new project, specify spring boot, let intellij build everything for me and throw me into the project, but then need to go back and do another new project/import.  The screenshot above was from creating a brand new spring boot project using spring intializr, not from an import.  I can watch youtube videos of people creating spring boot projects in seconds with no issues.

So I took my brand new spring boot project from above and tried to create a new project by importing the pom, but the project layout doesn't show any of the sources:

 

If I manually add modules and specify that I want to import from a POM structure, it doesn't detect anything.  If I say I want to add a new module from existing sources, I can select my main and test directory structures.  However, once it loads, it doesn't detect any facets and still gives me all kinds of errors about not being able to resolve symbols, and still gives me no options to run my project:

I'm baffled why this is so difficult.  I would think that if I used the Spring Boot wizard, it would build a working project for me.  Could something be wrong with my installation?

1

Just for sanity's sake, I'm going to try to create a new Spring Boot project again from scratch and step through what I'm doing.  

  1. Start up IntelliJ IDEA.  The welcome screen appears and I choose "Create New Project".
  2. On the "New Project" window, I select "Spring Initializr".  SDK is set to 1.8 and the Initalizr Server URL is https://start.spring.io.  I click "Next".
  3. On the next screen, I leave all the defaults, but change the name to "demo2".  
  4. On the next screen, I leave the Spring Boot Version at 1.4.0.  I only select the "Web" dependency and click next. 
  5. The next screen asks me for the project location.  I just leave the defaults and click "Finish".
  6. A popup appears and says there is a non managed pom, and I click on a link to add it as a maven project.

At this point I see my whole project structure, but again have no option to run my project.

 

In the project structure, under modules, I see the following: 

Facets says that "No facets are configured".  There is no run configuration.  If I add one, it shows a list and says it's hiding 17 that are irrelevant, but I don't see Spring Boot, so I click to show the "irrelevant" ones and Spring Boot appears.  I select Spring Boot and try to add my main class, but same as before, I type "com.example." and example immediately appears red and says it can't resolve symbol.

I'm starting to see thread dumps showing up in my logging directory, not sure if they are relevant:

http://pastebin.com/Kb9fzUnu

I'm at a total loss but have spent a ridiculous amount of time just trying to get one basic project set up.  

2

As requested, please share all the logs (https://intellij-support.jetbrains.com/hc/articles/207241085). There seems to be an issue with Maven on your system (it can't run and configure the project and download the dependencies for some reason).

For priority support it's recommended to report such problems by submitting a ticket to support, this way you can also share the logs privately.

1

I wiped my logs file when I created the new project so I could be sure to capture anything that may be happening in the most basic scenario of creating a new project.  No new logs file has appeared outside of the thread dump I posted.  There is a steady stream of new thread dumps as I leave the IDE open in the background and do nothing.

I use Maven extensively on this machine for several existing projects.  It works fine from both the command line and from inside NetBeans.  I did notice IJ was configured to use a bundled version of Maven instead of the one I have installed locally.  I changed it to use my existing installation of Maven and I will see if that has any effect.  

And as I was typing this response, a new idea.log just appeared:

http://pastebin.com/xHRB14az 

0

Can't notice any errors. Does it work with a more recent Maven version?

0

I found the issue!  I started poking into any maven setting I could find... I right clicked on the project, went down to Maven, then opened my settings.xml file.  IJ complained that it wasn't structured properly and there were multiple root elements.  Indeed, I had a profiles element for downloading sources and an activeProfiles element, but was missing the parent (and root) <settings> element.  Once I added the root element, IJ started doing all kinds of stuff and asked me to re-import the maven project.  I did, and now my basic demo project workings!  

I just switched over and imported one of my existing projects that has multiple maven modules.  It had to do a bit of processing and scanning, but when it finished everything seems to be working!

I'm very excited!  Thank you very much for your help!

2

Hi Jeff,

I am also facing the same issue. Can you please tell me where to make the changes. I am not seeing the maven settings.xml you have mentioned above when I do a right click on project. I got it. Now it is working. Thanks anyway

 

0
Avatar
Permanently deleted user

Right click on pom.xml, scroll to maven , when you hover over maven you will see create "settings.xml". That worked for me.

2
Avatar
Permanently deleted user

I don't believe this has anything to do with the settings.xml

I finally figured it out - at least it works for me now.  

1) Create a simple demo project using Spring Initializer.  unzip demo.zip

2) Create a new project in IDEA importing from the unzipped directory.   If you just accept all the defaults blindly - you actually get 3 (not 1) modules - demo, main, test.   main & test should not be modules - the wizard does allow you to uncheck them as modules but like you,  I had just accepted the defaults.

3) The problem is that modules main & test don't have the right classpath set - to see this go to Project Settings->Modules.  Click on main & look at dependencies (its mostly empty).  Go do the same for demo (here you see all the Maven downloaded jars in the dependencies/classpath)

4) To fix this,  in Project Modules, uncheck main & test so they are not modules.   This solves the problem.   There is now only 1 module - demo & the class path is set right for all source files.

3
Avatar
Permanently deleted user

If you have **multiple modules**(At intellij), Run> Edit configuration> Select springboot your application > Configuration tab> Working directory -> **$MODULE_WORKING_DIR$**

Also make sure pom.xml

- include tomcat, jasper embeded dependency
- make packaging war

Also, add springboot devtools that will help your jsp page edit without restart.

0
Avatar
Permanently deleted user

Ashok's fix worked for me, too. De-selecting Main and Test as modules is what I needed to get mine to work.

0

Ashok's Solution also worked for me. Thanks Ashok!!

1

I'm trying to use Ashok's fix, but I'm confused with his instruction to 'uncheck main & test'. Does he mean delete them with the image pictured below? If so, I tried doing this and then marking the source/resources folders in the root module, but once I re-build the gradle project, it re-generates the modules.

Any help?

1

Fixed it by:
Deleting .idea folder

Deleting build folder

File | Invalidate Caches / Restart

3
Avatar
Permanently deleted user

For me I simply didn't have the maven plugin installed! doh! Hope this helps others as I was experiencing exactly the same as the above but none of the solutions worked for me.

0

It stuck me almost a half day.  I found it is something wrong with the Bundled maven 3.    when I change it to a external maven home directory ,  every thing goes well.

0

Ahshok's solution worked for me as well. I first tried invalidating the cache but the problem came back. After deleting the extra modules, problem solved. Thanks Ashok!

0

java: error: release version 5 not supported Module market-dashboard SDK 17 does not support source version 1.5. Possible solutions: - Downgrade Project SDK in settings to 1.5 or compatible. Open project settings. - Upgrade language version in Maven build file to 17. Update pom.xml and reload the project. 

I can't execute the project, is there anyone help me?

 

0

The issue is that the intellij didn't detect the spring boot project.

Not sure how could it be solved?

0

I started from the spring boot demo project.

Just got the error like following



It seems not to detect the spring boot automatically.






There is some setting.


I got the error


Could you let me fix the issues step-by-step?

I am newbie of the intellijs, thanks in advance.
 

0

Please contact support at https://intellij-support.jetbrains.com/hc/requests/new. Attach the project zipped and the logs using Help | Collect Logs and Diagnostic Data. Also attach options\jdk.table.xml file from the Configuration directory: https://www.jetbrains.com/help/idea/directories-used-by-the-ide-to-store-settings-caches-plugins-and-logs.html#config-directory.

0

Please sign in to leave a comment.