This project was working fine. I was just playing around with Spring boot versions in pom.xml, imported some new maven projects, then saw that for those new projects, Springboot annotations and imports stopped working -
Cannot resolve @SpringBootApplication
pom.xml -
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.in28minutes.database</groupId>
<artifactId>database-demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>database-demo</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.11.RELEASE</version>
<!--<version>1.5.2.RELEASE</version>-->
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</project>
I have another setup, which is using spring boot 1.5.2.RELEASE. I checked that both the versions are there in my local .m2 repository. No clue on what is the issue.
It seems, all new projects imported are throwing the same issue. E.g. https://github.com/callicoder/spring-boot-actuator-demo
Update
I realised my main project, has some dependencies (maven repositories downloaded from a remote server). These are defined in .m2/settings.xml.
When I ran mvn install on command line, I get this error -
[ERROR] Failed to execute goal on project actuator-demo: Could not resolve dependencies for project com.example:actuator-demo:jar:0.0.1-SNAPSHOT: Failed to collect dependencies at org.springframework.boot:spring-boot-starter-actuator:jar:2.1.11.RELEASE: Failed to read artifact descriptor for org.springframework.boot:spring-boot-starter-actuator:jar:2.1.11.RELEASE: Could not transfer artifact org.springframework.boot:spring-boot-starter-actuator:pom:2.1.11.RELEASE from/to nexus (https://project.repository.com/repository/maven-public/): Failed to transfer file: https://project.repository.com/repository/maven-public/org/springframework/boot/spring-boot-starter-actuator/2.1.11.RELEASE/spring-boot-starter-actuator-2.1.11.RELEASE.pom. Return code is: 502 , ReasonPhrase:Bad Gateway. -> [Help 1]
I took a backup of the settings.xml and removed it. I ran mvn clean fresh, this time it downloaded artefacts from mvn remote repository and problem got resolved.
Not sure what is a proper way to switch settings.xml for my working project and demo projects, as former needs those settings.
.m2
folder. Also don't foget to check "online mode" which I found set one day and I wondered for hours why the new dependencies are not resolved. Give it a try :) β Nikolas Charalambidismvn dependency:tree -Dincludes=[groupId]:[artifactId]:[type]:[version]
to print your dependencies tree to a fike and see what dependencies and versions you are using. β Binyamin Regev