Endpoints just return 404

I'm testing my endpoints with curl but them always return 404 code curl -X POST -H "Content-Type: application/json" -d '{"name":"Chocolate"}' http://localhost:8080/latte/api/v1/flavors
* Host localhost:8080 was resolved.
* IPv6: ::1
* IPv4: 127.0.0.1
* Trying [::1]:8080...
* Connected to localhost (::1) port 8080
* using HTTP/1.x
> POST /latte/api/v1/flavors HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/8.14.1
> Accept: */*
> Content-Type: application/json
> Content-Length: 20
>
* upload completely sent off: 20 bytes
< HTTP/1.1 404
< Vary: Origin
< Vary: Access-Control-Request-Method
< Vary: Access-Control-Request-Headers
< X-Content-Type-Options: nosniff
< X-XSS-Protection: 0
< Cache-Control: no-cache, no-store, max-age=0, must-revalidate
< Pragma: no-cache
< Expires: 0
< X-Frame-Options: DENY
< Content-Type: application/json
< Transfer-Encoding: chunked
< Date: Wed, 18 Jun 2025 16:18:30 GMT
<
* Connection #0 to host localhost left intact
{"timestamp":"2025-06-18T16:18:30.837+00:00","status":404,"error":"Not Found","path":"/latte/api/v1/flavors"}
* Host localhost:8080 was resolved.
* IPv6: ::1
* IPv4: 127.0.0.1
* Trying [::1]:8080...
* Connected to localhost (::1) port 8080
* using HTTP/1.x
> POST /latte/api/v1/flavors HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/8.14.1
> Accept: */*
> Content-Type: application/json
> Content-Length: 20
>
* upload completely sent off: 20 bytes
< HTTP/1.1 404
< Vary: Origin
< Vary: Access-Control-Request-Method
< Vary: Access-Control-Request-Headers
< X-Content-Type-Options: nosniff
< X-XSS-Protection: 0
< Cache-Control: no-cache, no-store, max-age=0, must-revalidate
< Pragma: no-cache
< Expires: 0
< X-Frame-Options: DENY
< Content-Type: application/json
< Transfer-Encoding: chunked
< Date: Wed, 18 Jun 2025 16:18:30 GMT
<
* Connection #0 to host localhost left intact
{"timestamp":"2025-06-18T16:18:30.837+00:00","status":404,"error":"Not Found","path":"/latte/api/v1/flavors"}
19 Replies
JavaBot
JavaBot6mo ago
This post has been reserved for your question.
Hey @Franscis123$#! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
Franscis123$#
Franscis123$#OP6mo ago
package com.latteIceCream.latte.controller;

import java.util.List;

import com.latteIceCream.latte.domain.Flavor;
import com.latteIceCream.latte.dto.FlavorDTO;
import com.latteIceCream.latte.service.FlavorService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.Valid;

@RestController
@RequestMapping("/flavors")
public class FlavorController

{

@Autowired
FlavorService flavorService;

@PostMapping
public ResponseEntity<Flavor> postFlavor(@RequestBody Flavor flavor)

{

Flavor createdFlavor = flavorService.createFlavor(flavor);

if(createdFlavor == null){ return ResponseEntity.badRequest().build(); }

return ResponseEntity.ok(flavor);

}

@GetMapping("/{name}")
public ResponseEntity<Flavor> getFlavor(@PathVariable String name)

{

Flavor flavor = flavorService.readFlavor(name);

if(flavor == null){ return ResponseEntity.notFound().build(); }

return ResponseEntity.ok(flavor);

}

@PatchMapping("/{name}")
public ResponseEntity<Flavor> patchFlavor(@PathVariable String name, @RequestBody @Valid FlavorDTO flavorDTO)

{ return ResponseEntity.ok(flavorService.updateFlavor(flavorDTO)); }

@DeleteMapping("/{name}")
public ResponseEntity deleteFlavor(@PathVariable String name)

{

if(!flavorService.deleteFlavor(name)) { return ResponseEntity.internalServerError().build(); }

return ResponseEntity.noContent().build();

}

@GetMapping
public ResponseEntity<List<Flavor>> getAll(){ return ResponseEntity.ok(flavorService.getAllFlavors()); }

}
package com.latteIceCream.latte.controller;

import java.util.List;

import com.latteIceCream.latte.domain.Flavor;
import com.latteIceCream.latte.dto.FlavorDTO;
import com.latteIceCream.latte.service.FlavorService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.Valid;

@RestController
@RequestMapping("/flavors")
public class FlavorController

{

@Autowired
FlavorService flavorService;

@PostMapping
public ResponseEntity<Flavor> postFlavor(@RequestBody Flavor flavor)

{

Flavor createdFlavor = flavorService.createFlavor(flavor);

if(createdFlavor == null){ return ResponseEntity.badRequest().build(); }

return ResponseEntity.ok(flavor);

}

@GetMapping("/{name}")
public ResponseEntity<Flavor> getFlavor(@PathVariable String name)

{

Flavor flavor = flavorService.readFlavor(name);

if(flavor == null){ return ResponseEntity.notFound().build(); }

return ResponseEntity.ok(flavor);

}

@PatchMapping("/{name}")
public ResponseEntity<Flavor> patchFlavor(@PathVariable String name, @RequestBody @Valid FlavorDTO flavorDTO)

{ return ResponseEntity.ok(flavorService.updateFlavor(flavorDTO)); }

@DeleteMapping("/{name}")
public ResponseEntity deleteFlavor(@PathVariable String name)

{

if(!flavorService.deleteFlavor(name)) { return ResponseEntity.internalServerError().build(); }

return ResponseEntity.noContent().build();

}

@GetMapping
public ResponseEntity<List<Flavor>> getAll(){ return ResponseEntity.ok(flavorService.getAllFlavors()); }

}
dan1st
dan1st6mo ago
Can you show your application.properties?
Franscis123$#
Franscis123$#OP6mo ago
application.yml
# Other configs

server:

servlet:

context-path: /latte/api/v1
# Other configs

server:

servlet:

context-path: /latte/api/v1
package com.latteIceCream.latte.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.Customizer;
import org.springframework.security.config.annotation.SecurityConfigurerAdapter;
import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.web.DefaultSecurityFilterChain;
import org.springframework.security.web.SecurityFilterChain;

@Configuration
@EnableWebSecurity
public class SecurityConfig extends SecurityConfigurerAdapter<DefaultSecurityFilterChain, HttpSecurity>

{

@Bean
public BCryptPasswordEncoder passwordEncoder(){ return new BCryptPasswordEncoder(); }

@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception

{

http
.authorizeHttpRequests(auth -> auth
.anyRequest().permitAll())
.httpBasic(Customizer.withDefaults())
.csrf(AbstractHttpConfigurer::disable);

return http.build();

}

@Bean
public AuthenticationManager authenticationManager(AuthenticationConfiguration configuration) throws Exception

{ return configuration.getAuthenticationManager(); }

}
package com.latteIceCream.latte.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.Customizer;
import org.springframework.security.config.annotation.SecurityConfigurerAdapter;
import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.web.DefaultSecurityFilterChain;
import org.springframework.security.web.SecurityFilterChain;

@Configuration
@EnableWebSecurity
public class SecurityConfig extends SecurityConfigurerAdapter<DefaultSecurityFilterChain, HttpSecurity>

{

@Bean
public BCryptPasswordEncoder passwordEncoder(){ return new BCryptPasswordEncoder(); }

@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception

{

http
.authorizeHttpRequests(auth -> auth
.anyRequest().permitAll())
.httpBasic(Customizer.withDefaults())
.csrf(AbstractHttpConfigurer::disable);

return http.build();

}

@Bean
public AuthenticationManager authenticationManager(AuthenticationConfiguration configuration) throws Exception

{ return configuration.getAuthenticationManager(); }

}
dan1st
dan1st6mo ago
Can you show your pom.xml?
Franscis123$#
Franscis123$#OP6mo ago
I use gradle
plugins {

java
id("org.springframework.boot") version "3.5.0"
id("io.spring.dependency-management") version "1.1.7"


}

group = "com.latteIceCream"
version = "0.0.1-SNAPSHOT"

java { toolchain { languageVersion = JavaLanguageVersion.of(24) } }

repositories { mavenCentral() }

dependencies {

implementation("org.springframework.boot:spring-boot-starter-data-jpa")
implementation("org.springframework.boot:spring-boot-starter-security")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.boot:spring-boot-starter-validation")

runtimeOnly("org.mariadb.jdbc:mariadb-java-client")

testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("org.springframework.security:spring-security-test")

testRuntimeOnly("org.junit.platform:junit-platform-launcher")

}

tasks.withType<Test> { useJUnitPlatform() }
plugins {

java
id("org.springframework.boot") version "3.5.0"
id("io.spring.dependency-management") version "1.1.7"


}

group = "com.latteIceCream"
version = "0.0.1-SNAPSHOT"

java { toolchain { languageVersion = JavaLanguageVersion.of(24) } }

repositories { mavenCentral() }

dependencies {

implementation("org.springframework.boot:spring-boot-starter-data-jpa")
implementation("org.springframework.boot:spring-boot-starter-security")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.boot:spring-boot-starter-validation")

runtimeOnly("org.mariadb.jdbc:mariadb-java-client")

testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("org.springframework.security:spring-security-test")

testRuntimeOnly("org.junit.platform:junit-platform-launcher")

}

tasks.withType<Test> { useJUnitPlatform() }
dan1st
dan1st6mo ago
How are you running the project? What is the package of the main class?
Franscis123$#
Franscis123$#OP6mo ago
From IntelliJ IDE package com.latteIceCream.latte;
dan1st
dan1st6mo ago
Are you using IntelliJ Community or Ultimate?
Franscis123$#
Franscis123$#OP6mo ago
Community
dan1st
dan1st6mo ago
Can you add Spring actuator to the project for testing?
Franscis123$#
Franscis123$#OP6mo ago
Yeah, done
dan1st
dan1st6mo ago
Can you temporarily add the properties management.endpoint.beans.enabled=true and management.endpoints.web.exposure.include=beans? and then access /actuator/beans might be /latte/api/v1/actuator/beans
Franscis123$#
Franscis123$#OP6mo ago
I added them and try it curl http://localhost:8080/latte/api/v1/actuator/beans but it gives me the same error
dan1st
dan1st6mo ago
what without the /latte/api/v1? Did you restart the project after reloading?
Franscis123$#
Franscis123$#OP6mo ago
I restarted it and tried both but throws 404
dan1st
dan1st6mo ago
what without the beans at the end?
Franscis123$#
Franscis123$#OP6mo ago
The same
JavaBot
JavaBot6mo ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.

Did you find this page helpful?