Ya estoy inscrito ¿Todavía no tienes acceso? Nuestros Planes
Ya estoy inscrito ¿Todavía no tienes acceso? Nuestros Planes
Solucionado (ver solución)
Solucionado
(ver solución)
2
respuestas

[Duda] Error 404 SpringBoot3

Buen día, estoy utilizando tanto el IDE como Spring Initializer para crear el proyecto, sin embargo tengo un problema y es el error 404:

GET http://localhost:8080/hello

HTTP/1.1 404 
Vary: Origin
Vary: Access-Control-Request-Method
Vary: Access-Control-Request-Headers
Content-Type: application/json
Transfer-Encoding: chunked
Date: Wed, 06 Sep 2023 17:14:17 GMT
Keep-Alive: timeout=60
Connection: keep-alive

{
  "timestamp": "2023-09-06T17:14:17.403+00:00",
  "status": 404,
  "error": "Not Found",
  "message": "No message available",
  "path": "/hello"
}
Response file saved.
> 2023-09-06T121417.404.json

El codigo que use es este:

package med.voll.api;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class ApiApplication {

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

}

Y el Controller es el siguiente:

package med.voll.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

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

El output cuando se inicia la app es el siguiente:


  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v3.1.3)

2023-09-06T12:29:13.717-05:00  INFO 6037 --- [  restartedMain] med.voll.api.ApiApplication              : Starting ApiApplication using Java 17.0.7 with PID 6037 (/Users/kemmeralexandertorresgomez/Library/Mobile Documents/com~apple~CloudDocs/Alura/SpringBoot3/api/target/classes started by kemmeralexandertorresgomez in /Users/kemmeralexandertorresgomez/Library/Mobile Documents/com~apple~CloudDocs/Alura/SpringBoot3/api)
2023-09-06T12:29:13.720-05:00  INFO 6037 --- [  restartedMain] med.voll.api.ApiApplication              : No active profile set, falling back to 1 default profile: "default"
2023-09-06T12:29:13.758-05:00  INFO 6037 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2023-09-06T12:29:13.759-05:00  INFO 6037 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2023-09-06T12:29:14.363-05:00  INFO 6037 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2023-09-06T12:29:14.370-05:00  INFO 6037 --- [  restartedMain] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2023-09-06T12:29:14.370-05:00  INFO 6037 --- [  restartedMain] o.apache.catalina.core.StandardEngine    : Starting Servlet engine: [Apache Tomcat/10.1.12]
2023-09-06T12:29:14.403-05:00  INFO 6037 --- [  restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2023-09-06T12:29:14.403-05:00  INFO 6037 --- [  restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 644 ms
2023-09-06T12:29:14.599-05:00  INFO 6037 --- [  restartedMain] o.s.b.d.a.OptionalLiveReloadServer       : LiveReload server is running on port 35729
2023-09-06T12:29:14.621-05:00  INFO 6037 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2023-09-06T12:29:14.627-05:00  INFO 6037 --- [  restartedMain] med.voll.api.ApiApplication              : Started ApiApplication in 1.188 seconds (process running for 1.796)

Ya reinicie el servicio en varias ocasiones pero sigue saliendo lo mismo.

2 respuestas

Hola; Creo que no es: public class HelloControl {

Debe ser: public class HelloController {

solución!

Ya lo solucione, al parecer el main no estaba encontrando la clase HelloController por que estaba en otro paquete por fuera.