Search code examples
spring-bootspring-mvcspring-data-jpajava-ee-8

The controllers doens't work on my spring boot application


I don't know what is happening but im doing everything good.

The application starts well

[2m2023-04-22T03:23:17.326+02:00[0;39m [32m INFO[0;39m [35m55932[0;39m [2m---[0;39m [2m[           main][0;39m [36mc.alibou.security.SecurityApplication   [0;39m [2m:[0;39m Starting SecurityApplication using Java 17.0.6 with PID 55932 (D:\Descargas\spring-boot-3-jwt-security-main\spring-boot-3-jwt-security-main\target\classes started by luis_ in D:\Descargas\spring-boot-3-jwt-security-main\spring-boot-3-jwt-security-main)
[2m2023-04-22T03:23:17.328+02:00[0;39m [32m INFO[0;39m [35m55932[0;39m [2m---[0;39m [2m[           main][0;39m [36mc.alibou.security.SecurityApplication   [0;39m [2m:[0;39m No active profile set, falling back to 1 default profile: "default"
[2m2023-04-22T03:23:18.034+02:00[0;39m [32m INFO[0;39m [35m55932[0;39m [2m---[0;39m [2m[           main][0;39m [36mo.s.b.w.embedded.tomcat.TomcatWebServer [0;39m [2m:[0;39m Tomcat initialized with port(s): 8080 (http)
[2m2023-04-22T03:23:18.042+02:00[0;39m [32m INFO[0;39m [35m55932[0;39m [2m---[0;39m [2m[           main][0;39m [36mo.apache.catalina.core.StandardService  [0;39m [2m:[0;39m Starting service [Tomcat]
[2m2023-04-22T03:23:18.042+02:00[0;39m [32m INFO[0;39m [35m55932[0;39m [2m---[0;39m [2m[           main][0;39m [36mo.apache.catalina.core.StandardEngine   [0;39m [2m:[0;39m Starting Servlet engine: [Apache Tomcat/10.1.4]
[2m2023-04-22T03:23:18.128+02:00[0;39m [32m INFO[0;39m [35m55932[0;39m [2m---[0;39m [2m[           main][0;39m [36mo.a.c.c.C.[Tomcat].[localhost].[/]      [0;39m [2m:[0;39m Initializing Spring embedded WebApplicationContext
[2m2023-04-22T03:23:18.128+02:00[0;39m [32m INFO[0;39m [35m55932[0;39m [2m---[0;39m [2m[           main][0;39m [36mw.s.c.ServletWebServerApplicationContext[0;39m [2m:[0;39m Root WebApplicationContext: initialization completed in 761 ms
[2m2023-04-22T03:23:18.436+02:00[0;39m [32m INFO[0;39m [35m55932[0;39m [2m---[0;39m [2m[           main][0;39m [36mo.s.b.w.embedded.tomcat.TomcatWebServer [0;39m [2m:[0;39m Tomcat started on port(s): 8080 (http) with context path ''
[2m2023-04-22T03:23:18.444+02:00[0;39m [32m INFO[0;39m [35m55932[0;39m [2m---[0;39m [2m[           main][0;39m [36mc.alibou.security.SecurityApplication   [0;39m [2m:[0;39m Started SecurityApplication in 1.412 seconds (process running for 1.872)

this is the main class

@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, SecurityAutoConfiguration.class})
@ComponentScan("com.alibou.security.user")
public class SecurityApplication {

    public static void main(String[] args) {
        SpringApplication.run(SecurityApplication.class, args);
    }

}

and this is the structure of the project

enter image description here

this is one controller sample

@RestController
public class Controller {

    @GetMapping("/hello")
    public String helloWorld() {
        return "Hello World";
      }
}

and this is an input from POSTMAN

enter image description here

nothing is working, i swear i didnt have this problems years ago, now even the most simple thing is not working anymore.

Any hint?


Solution

  • Baeldung has a good explanation on how these annotations work here: https://www.baeldung.com/spring-component-scanning.

    Essentially, (from their site):

    We use the @SpringBootApplication annotation, but it's a combination of three annotations:

    @Configuration
    @EnableAutoConfiguration
    @ComponentScan
    

    Only the location of the configuration class matters, as component scanning starts from its package by default.

    Since you have used the @SpringBootApplication, the scanning will start from there, so I dont think you need to have the @ComponentScan annotation here. Unless you are trying to achieve something else that you did not mention on the question.