When I create any contoller and add mapping for it, 404 page appears in any mapping I have created.Annotation Component scan does not work. All works in my old projects. I was trying move my app class to controller package. It could not help. And I was trying add component scan annotation. Unfortunately, it could not help as well
This is my Application class
package by.yankavets.jetbank;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class JetBankApplication {
public static void main(String[] args) {
SpringApplication.run(JetBankApplication.class, args);
}
}
This is my only controller class
package by.yankavets.jetbank.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class CardController {
@GetMapping("/card")
public String card() {
return "This is new card";
}
}
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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>by.yankavets</groupId>
<artifactId>JetBank</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>JetBank</name>
<description>JetBank</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
application.properties
spring.security.user.password=1111
>Solution :
Check you path to application. If it contains any spaces, you should remove them or move your app to another folder without spaces in path and re-run it.
Good: /home/user/dev/spring-app
Bad: /home/user/my dev/spring app
On screenshot you provided, I noticed folder name with space Spring Framework
Hope it will helps you 🙂