IntelliJ运行错误SpringBoot版本,mvn与java jar运行正常
Hey there, I’ve run into this exact kind of dependency mismatch issue before with IntelliJ, so let’s walk through the most likely fixes to get your Spring Boot 2.0.1.RELEASE running correctly when you debug or run your app in the IDE.
1. Refresh Maven Dependencies & Clear IntelliJ Caches
First up, IntelliJ often holds onto old dependency metadata in its cache, which can cause this kind of version mismatch.
- Open the Maven sidebar in IntelliJ (usually on the right side), then click the circular refresh icon to sync your
pom.xmldependencies with the IDE. - Next, go to
File → Invalidate Caches / Restart...and select Invalidate and Restart. This will wipe out any stale cache data and reload your project from scratch—this is a magic fix for most IDE-related dependency issues.
2. Check Your Run/Debug Configurations
Sometimes the run configuration itself might be overriding your pom.xml settings:
- Click the run/debug dropdown in the top-right corner of IntelliJ and select Edit Configurations.
- Find your Spring Boot application configuration, then head to the Configuration tab. Make sure the "Command line" field doesn’t have any manual overrides that force Spring Boot 2.0.0.RELEASE.
- Also check the Environment tab for any VM options that might be specifying an older version.
3. Audit Your Dependency Tree for Hidden Overrides
Even if your parent pom is set to 2.0.1.RELEASE, a transitive dependency might be pulling in 2.0.0.RELEASE:
- Right-click your
pom.xmlfile and select Show Dependencies to open the Maven Dependency Analyzer. - Use the search bar to look for
spring-bootrelated artifacts. If you see any entries using 2.0.0.RELEASE, trace back to which dependency is introducing it. - To fix this, you can either add that specific dependency to your
pom.xmlwith the 2.0.1.RELEASE version, or use a<dependencyManagement>section to lock in the correct version for all Spring Boot artifacts.
4. Verify IntelliJ is Using the Correct Maven Installation
If IntelliJ is using a different Maven version than your command line, it might resolve dependencies differently:
- Go to
File → Settings → Build, Execution, Deployment → Build Tools → Maven. - Check that the Maven home directory points to the same Maven installation you use when running
mvn clean packagefrom the command line. - Also ensure the User settings file is pointing to your correct
settings.xml(to avoid pulling dependencies from a cached or incorrect repository).
5. Test with Command Line First
Since you mentioned mvn clean package works, try running your app from the command line with mvn spring-boot:run. If this uses 2.0.1.RELEASE correctly, that confirms the issue is entirely within IntelliJ’s configuration—go back to steps 1 and 2 to double-check your cache and run settings.
内容的提问来源于stack exchange,提问作者DuckyDisciple

