#SpringBootApplication cannot be resolved to a type for Spring Boot version 2.0.3 - spring

I have created a project using Spring Initializr with Spring Boot V-2.0.3
I am using STS 3.9.4 on Ubuntu Machine.
I am getting these errors:
The import org.springframework.boot.autoconfigure.SpringBootApplication cannot be resolved
SpringBootApplication cannot be resolved to a type
I have already tried deleting the repository folder from .m2 folder and hitting the following commands
mvn clean dependency:tree
mvn clean compile
But still errors were not resolved than I added an Extra Dependency to the POM file
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-autoconfigure -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
<version>2.0.3.RELEASE</version>
</dependency>
I have updated the project by following the below steps after each step performed but still the error is not resolved.
STS Right click on project -> Maven -> Update Project

Go to STS Right click on project -> Maven -> Update Project.

Related

Why doesn't intelliJ install the dependency

I'm trying to add the following dependency in the pom.xml with IntelliJ
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
The issue is that the spring-boot-devtools does not get added in my "External libraries" folder as it should as per https://www.jetbrains.com/help/idea/work-with-maven-dependencies.html#maven_dependency_multi_module
IntelliJ gives me the error :
Dependency 'org.springframework.boot:spring-boot-devtools:3.0.1' not found
Why is the new dependency not added properly ?
In order to have the dependency installed, you have to right click on the pom.xml > Maven > Reload project.
The dependency gets added in the Externam Libraries folder and the error in pom.xml disappears

Import of jar in IntelliJ is successful and imports are resolved but mvn clean install and package fails

Some classes in my spring boot maven project were showing errors on some imports , so I had to add an external jar dependency in my IntellIJ (Community) . After adding it all the errors are gone , and i can see the jar is listed inside external libraries in IntelliJ . I try to run the spring boot project , works fine . But when i try to do a mvn clean install or mvn clean on the project directory , it fails showing import errors on the same classes for which purpose i had added the jar . I tried re-building the project , invalidating caches , but issue still remains the same . I am not able to understand if adding the JAR has resolved the import errors , and project also starts , why mvn phases are having failure as if no jar is added ?
In a Maven based project you must manage project build configuration, including dependency management in Maven pom.xml build files, not adding it via IDE interface. So you need to add the required dependencies using the Maven's dependency management mechanism, simply inside Maven dependencies section. e.g.
<dependencies>
...
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.3.4.RELEASE</version>
</dependency>
...
</dependencies>
And by the way the IDE helps you with that.

Failed to add RXjava dependency from pom file in intellij

I tried to open a maven project with Intellij. The project was originally created on eclipse and worked fine.
However I receive an error
Dependency 'io.reactivex.rxjava2:rxjava:2.2.19' not found
(I get the same error if I try to start a new project in Intellij with the rxjava dependency)
Here is my dependencies section in the POM file:
<dependencies>
<dependency>
<groupId>io.reactivex.rxjava2</groupId>
<artifactId>rxjava</artifactId>
<version>2.2.19</version>
</dependency>
</dependencies>
What am I doing wrong?
running
mvn clean install
from command line, solved the issue

Spring boot starter web project : eclipse not able to resolve annotations #RestController and #RequestMapping

I started to build spring boot project via following one of the online courses. When completed initial configuration and code, eclipse was not able to resolve #RestController and #RequestMapping annotations even though I have following in my POM file :
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.1.RELEASE</version>
</parent>
and in dependency section, I have:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
Eclipse will only be able to resolve these annotations if appropriate jar is in your 'maven dependecies' folder under 'project manager' in eclipse.
How did I troubleshoot this :
Step 1 :
first we need to know which jar file will be containing these annotation classses. Try to look up google to get hints and still better expand those jar files under 'maven dependecies' folder under 'project manager' in eclipse to see if they have similar package structure that is leading upto specific class.
In my case this time, while I was expanding jar files, 'spring-web-4.2.4.RELEASE.jar' failed to expand. Next I went to local .m2 folder to see if this file is properly downloaded.
Surprisingly, I could open the jar file and see the classes.
Step 2 :
I deleted the files under 'm2\repository\org\springframework\spring-web\4.2.4.RELEASE'
Step 3 :
Went back to eclipse > right click project > maven > update project
Step 4 :
select project and also select 'force update snapshot/releases' option and hit 'ok'
above should download files that you deleted again and it should now successfully expand under 'maven dependencies' in project explorer.
Post this my error was resolved as eclipse was able to find the classes.

ReflectionToStringBuilder errors in Maven Project

Some of my Roo generated .aj files seem to be generating errors as below. I can see commons-lang3-3.1.jar in my Maven Dependencies. I have added this to my pom.xml
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.1</version>
</dependency>
Failed to execute goal
org.codehaus.mojo:aspectj-maven-plugin:1.2:compile (default) on
project AdminDirect-Model: Compiler errors : [ERROR] error at return
ReflectionToStringBuilder.toString(this,
ToStringStyle.SHORT_PREFIX_STYLE);
I have a multi-module project, and when in STS I try to do a right click and Update Project, I get another annoying error saying "Problems Encountered while setting project description"...although this is probably a separate issue.
As an aside if anyone knows of the correct workflow to create a multi-module spring roo, JSF, JPA application (Model and Web tier under a parent module) that would be greatly appreciated.
I deleted the .m2/repository folder contents and forced a fresh download using Maven Update Project and then forced a refresh of snapshots. Seems to work, jars must have been corrupt?
tomcat server fails to start the server and application in STS

Resources