1,614 questions
0
votes
1
answer
85
views
Spring Boot @Valid returns just "Bad Request" message instead of my custom message
I just want to get my custom message in Swagger response (not just "Bad Request")
@RestController
@RequestMapping
@RequiredArgsConstructor
public class GenUrlController {
private final ...
0
votes
1
answer
152
views
Spring Boot 3.x — @RestControllerAdvice not catching custom exceptions
I recently upgraded to Spring Boot 3.5 (Jakarta packages) and noticed my global exception handler isn’t being triggered.
@RestController
public class UserController {
@GetMapping("/test")...
1
vote
1
answer
83
views
Do not load parent controller if child controller exists
I use Spring Boot 3.3.4 and Java 21.
I have several Spring Boot web application that use the same common library :
App1
App2
App3
Common
In this common library, I have a @RestController used to ...
1
vote
1
answer
69
views
Spring boot 3.4.7 @Valid validation allows empty json on a PUT/PATCH rest endpoint
With the use spring boot 3.4.7 noticing a below change
We have a pojo with lomobok annoatiaon
import org.springframework.validation.annotation.Validated;
@Builder
@Validated
public record AppState(
...
0
votes
1
answer
70
views
Binder.getTarget() is null, can not binding custom key, value using initBinder in Spring 6.x
I am having trouble binding custom key and value map after migrating to 6.x where binder.getTarget() comes out to be null. I debugged and it turnes out binder target is set later point of time. Is ...
2
votes
0
answers
43
views
Spring Boot REST endpoint seems to not execute Neo4j Java driver statements (JHipster + Neo4jConfig + Neo4jService) → no Cypher run
I am integrating Neo4j into my JHipster 8.5.0 / Spring Boot 3.3.0 application.
I have configured a Neo4jConfig with a Driver bean, a Neo4jService to send Cypher statements, and a REST endpoint /api/...
0
votes
0
answers
80
views
How does spring-boot 3.5.0 evaluate which java.time.format.ResolverStyle to be used depending on the local?
I have a Restcontroller with a parameter with a LocalDate like this:
@RequestParam @Schema(requiredMode = REQUIRED) @NonNull final LocalDate startDate
When calling the endpoint with a Swedish ...
0
votes
1
answer
48
views
Form URL encoded data and Spring Rest Controller, data coming as null
We are getting a request from 3rd part and in our logs the body is printed like this
"body":"Response=%7B%22TransactionType%22%3A1%2C%22Approved%22%3Afalse%2C%22TransactionIdentifier%22%...
1
vote
0
answers
23
views
Testing RestController class with HATEOAS links
I am working through the Amazon Junior Dev Certificate on Coursera and finishing up the course on Spring Boot APIs. The current lab I am working on is requiring me to write unit tests for a ...
0
votes
1
answer
183
views
How to fix this: Resolved [org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'POST' is not supported
I have a Spring Boot REST API, and it works perfectly when tested via Postman—all HTTP methods function as expected. However, when I try to interact with the API from the client-side application, I ...
0
votes
0
answers
84
views
Having more control over "@RequestBody Entity entity" when creating/updating a record
I am switching to Java/Spring from another development stack and I am very confused about how in Spring some things are done.
One of the issues is the magical conversion of request body parameters ...
0
votes
2
answers
52
views
Spring restcontroller with RequestParam String conflcting in controller
I have a Restcontroller with 4 methods, but I can't use the calls, I always get the error: "message": "No static resource api/corp.",
I need method with string like:
localhost:...
1
vote
2
answers
282
views
How to perform redirect in HTMX based on response from the Spring boot JSON rest API?
I am checking examples of Htmx + Spring. All examples use server-side template engines ( like Thymeleaf or Jte).
Htmx expects an HTML response from Spring, but Nowadays, most Spring applications ...
0
votes
1
answer
470
views
Content-Length header is removed from HEAD response
We have a REST controller with a HEAD method but no GET method. We don't want the client to be able to retrieve the resource, but we do want them to be able to know whether it exists and how big it is....
1
vote
3
answers
121
views
Spring Boot Controller Not Registering and 404 Error on POST Request
I’m working on a Spring Boot application, and I’m having trouble getting my controller to register correctly. When I try to POST data to the /student/add endpoint, I receive a 404 error, indicating ...
0
votes
1
answer
491
views
Why I am not able to send list of strings as json response in Spring Rest?
I have built a simple spring rest application that has just one rest controller.
DemoRestController.java:
import java.util.Arrays;
import java.util.List;
import org.springframework.http.MediaType;
...
0
votes
1
answer
115
views
Unexpected 401 error at testing RestController
`
I'm trying to test the login method by adding a user, and when I want to login, I get a 401 response insted of 200
UserController
/**
* Login form
* @param user the user we are trying to log in ...
1
vote
2
answers
175
views
Spring @RestController and @PathVariable queuing bug?
I've noticed some odd behavior with my SpringBoot micro service. I'm using spring mvc, springboot 3.3.3 and Java 21.
Consider the following code in a Controller (annotated with @RestController and ...
0
votes
1
answer
282
views
Best way to handle returning success (i.e. 20X) responses AND failure (i.e. 4XX, 5XX etc..) responses in Java Spring Boot?
I know within the Spring @RestController class, we can do something like:
@GetMapping("/"
public ResponseEntity<Weather> getWeatherRecordsById(@PathVariable Integer id){
...
0
votes
1
answer
85
views
Id getting changed in spring boot request
I have created a project with spring boot and MongoDB as database. I am trying to hit a get request to fetch the data that I have saved in the database. For fetching that I am passing an id from the ...
0
votes
1
answer
75
views
How to implement exception handling in a mixed MVC and REST Spring application?
Spring Boot 3.2.x / Spring Web 6.1.x
In an app with both MVC controllers (returning HTML pages via JSP) and REST controllers, how can I implement global exception handling such that MVC controller ...
0
votes
1
answer
45
views
Getting error while retriving data using Rest API Spring MVC
org.springframework.web.client.RestClientException: Could not extract response: no suitable HttpMessageConverter found for response type [class com.eprocurement.common.beans.ResponseBean] and content ...
0
votes
1
answer
51
views
Spring MVC pass object from list to post-endpoint
I have a spring-controller with a post-endpoint that receives a WordDto. Another get-endpoint puts a list of WordDtos in the ModelMap and shows a jsp-file. In the jsp-file, I show each entry of the ...
0
votes
2
answers
64
views
how to return the xml or json respoonse based on url extension
I have a java service which is built on jaxrs and it is returning the response based on url extension.
For example: http://localhost:8080/employees returns xml by default, http://localhost:8080/...
0
votes
2
answers
212
views
How to Access a Request-Scoped Bean in a Spring Exception Handler?
I need to log trace information using a Tracer bean, which is request-scoped, in both my REST method and exception handler. The Tracer bean is consumed in the REST method to log the trace information ...
-1
votes
1
answer
43
views
My RestController is not being reached. How do i fix it?
I'm trying to build a simple registration web app using reactJS and Spring Boot. However, database(Postgresql) doesnt seem to be receiving anything.
here is my frontend submit code, where REGISTER_URL ...
-1
votes
1
answer
114
views
Issue in spring boot 2.7.6 returning NoHandlerException for GET '/v3/test/'
I am using spring boot 2.7.6, Gradle 8.6 and here is the application.properties file
spring.mvc.servlet.path = /v3
spring.mvc.throw-exception-if-no-handler-found = true
spring.mvc.static-path-pattern=/...
0
votes
1
answer
70
views
Is it a good practice to call rest controller function in another rest controller function of the same controller based on request type?
Let's assume, I have 2 REST Endpoints and the second of them calls internally first one. The POST endpoint will behave like normal GET endpoint, but because of very large Set of dependentCategories, I ...
1
vote
0
answers
40
views
Spring boot @RestController throwing 404
I have two rest controllers on the same package level with following code:
First controller:
@Slf4j
@AllArgsConstructor
@RestController
@RequestMapping(API + NO_AUTH + "/payments/...
0
votes
1
answer
220
views
Validation for a collection of objects
I am writing the backend part of an application in which I want to implement the ability to accept and validate for each object in the list.
I know about two annotations that can do this:
@Valid is ...
0
votes
0
answers
63
views
Is it possible to accept file without any key in multipart-formdata? (blank key)
In multipart formdata we accept the parts as with key-value pairs, is it possible to handle request with file without any key?
curl --location --request GET 'endpoint'
--form '=@"/C:/Users/User/...
-2
votes
1
answer
69
views
Java Spring Softwaretest json response is empty. Why?
I'm working on a fun project with some random person data (from java-faker) to learn more aboud java, spring, api, thymeleaf, softwaretests...
-> my-project-from-gitlab
Besides many small problems ...
0
votes
1
answer
101
views
Custom LoginController in Spring Security and post with Angular
Im trying to create my own LoginController so i can watch the data flow more closely, but either my post method is wrong or my controller is missing something.
Whenever I try to send a login request ...
3
votes
3
answers
835
views
Java SpringBoot @PathVariable on RestController
I have the following @RestController:
package io.github.paulmarcelinbejan.coandaairlines.reservationsystem.adapters.inbound.controller.rest;
import java.util.List;
import org.springframework.http....
0
votes
1
answer
82
views
QueryDsl: Customize predicate with Rest Controller
public Page<DemoDto> find(
@QuerydsPredicate(root = DemoEntiy.class) final Predicate predicate,
@PageableDefault(size = 100)
@SortDefault(sort = "id", direction = Sort....
0
votes
1
answer
36
views
Rest Controller design pattern
is it bad to have pojo for all supported filter params in search api rather than taking each one with @RequestParam .
Let's say i have api for search car and supported filter for cars
brand , model ,...
0
votes
1
answer
343
views
Spring boot RestControllers doesn't work with library containing @Entities
I have a spring boot (3.2.1) application that run on java 17. I also have library that contains @Entity annotations. I am connection to database using spring boot default Hibernate. I am able to ...
0
votes
1
answer
184
views
How to make programmatically a call to /oauth/token from the same application where we have it without actual http call?
I have a case, where I need to get access token without http call to predefined by Oauth Spring Security /oauth/token endpoint, but instead, have a call for some api, available for the anonymous user, ...
0
votes
3
answers
171
views
problem - "404 error" for localhost:8081/question/allQuestions
application properties:
# Database Connection Properties
spring.datasource.url=jdbc:mysql://localhost:3306/quizmaker
spring.datasource.username=root
spring.datasource.password=Corona@123
# Specify ...
1
vote
2
answers
312
views
Parameter 0 of constructor in com.example.service.QuestionService required a bean of type 'com.example.Dao.QuestionDao' that could not be found
Description:
Parameter 0 of constructor in com.example.service.QuestionService required a bean of type 'com.example.Dao.QuestionDao' that could not be found.
Action:
Consider defining a bean of type '...
0
votes
1
answer
68
views
JSON returns only the last entry of a Hashmap property via Spring Boot Rest Controller
I have a Map<Object, List> property. It correctly persists to SQL and a Spring Boot Repository correctly returns the Map. However, the JSON response from a Spring Boot Rest Controller only ...
0
votes
2
answers
651
views
How to fix this Error related with entityManqagerFactory?
`2024-01-14T20:25:05.873+05:30 INFO 12272 --- [ main] c.l.s.cruddemo.CruddemoApplication : Starting CruddemoApplication using Java 17.0.2 with PID 12272 (C:\Users\Anand\Desktop\dev-...
0
votes
3
answers
3k
views
@ManyToOne and @OneToMany adding and retrieving problem in springboot
I am encountering a problem in my Spring Boot JPA application related to relationships between the Owner and Car entities. The issue arises when attempting to associate a new Car with an existing ...
2
votes
3
answers
1k
views
How to properly use UUID as @PathVariable to hide sensitive data? REST API w/ Spring Boot
I have this basic delete request:
@DeleteMapping("/{id}")
public ResponseEntity<String> deleteSubscription(@PathVariable Long id) {
subscriptionService.deleteSubscription(id);
...
1
vote
1
answer
783
views
perfoming a Junit test with JsonPath not working
I am running a unit test on a rest controller method addUser() which executes successfully without JSON path. Anytime I try to use jsonPath to perform strict data assertion to verify the content of ...
0
votes
0
answers
163
views
Custom json Converter to fail on unknown properties but the response is not json
I implemented a custom converter to fail on unknown properties. I have a Front connected to FirstBackend and FirstBackend connected to SecondBackend.
i m on a springboot v2.7.14
this is my converter :
...
1
vote
1
answer
314
views
Spring REST Endpoint: 404 requested resource is not available error
I created spring boot starter project with Rest application. When trying to run the application as Run on server it will redirect to web browser with URL till context-path but after adding endpoints ...
7
votes
4
answers
6k
views
Is it possible to use Oauth2 authentication with the new RestClient?
With WebClient I use this code to make web client work with a Spring Resource Server endpoint.
Is it possible to make this code work with the new RestClient?
@Bean
UserClient userClient(...
0
votes
1
answer
4k
views
OpenAPI Swagger API not sending "Authorization" header along the API call
Environment :
Java 17
Service is on Spring Boot 3
OpenAPI dependencies : 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.1.0',
'org.springdoc:springdoc-openapi-starter-common:2.1.0',
'...
0
votes
0
answers
308
views
No mapping for POST. 404 Not Found
Please help if you have any idea why it's not working. I have been trying to test it with Postman for hours but no luck. I am trying to test my API with Postman but every time I try to send a post I ...