I have created a reusable method that returns the headers, status, and body of an HTTP call using the Spring webclient’s exchange method. I want to capture the 4xx and 5xx errors in the method itself and log the response body. However, i am not able to return/throw custom exception when 4xx or 5xx error occurs. Here is the reusable
Tag: spring
Spring Boot: using SpEL collection selection from YAML in @ConditionalOnExpression
I have a Spring Boot application with a YAML configuration that contains a feature list like this: I would like to use @ConditionalOnExpression to conditionally initialize beans related to those features, identifying them by keys. Since “features” property is a list, it seems I need collection selection to do this. I have tried these two options for the annotation’s value:
Run code without transaction in transactional mehod spring
I have service like this: How can I run method2 without transaction or in new transaction? Can I run in my controller class this 2 method like this: Answer @Transactional is powered by Aspect-Oriented Programming. Therefore, processing occurs when a bean is called from another bean. You can resolve this problem by self-inject create another bean.
Prototyped bean not triggering Scheduled method in Spring Boot
I’m using Java 17, spring-boot 2.7.3 and spring 5.3.22 dependencies. I have prototyped beans as follows: My application class: I annotated the InsertTransactionDetailsByScheduleAPIInteractor also as prototype in order to have a new instance of the inner beans per schedule execution, but somehow the @Scheduled method only runs when I have a singleton InsertTransactionDetailsByScheduleAPIInteractor bean, which in my use case I
Store bearerToken until expires
I have an application that consumes a REST service from another server, which has its own authentication method to be able to consume its services. Today, for each request we have, I am calling the authentication service then i receivethe bearerToken (which has a duration of 3 hours) and after that I call the endpoint I want to use. The
Mockito not working when using Model Mapper
I have an User class: And an UpdateUserDTO class: And an UserDTO class: I’ve used Model Mapper to map the updated fields from updateUserDTO to user, which comes from the DB. My test class looks like this: But the first Mockito.when() line does not even compile, because mapper.map() is a void method, so it does not expect any return values.
Nested JSON in JSON
How can I form JSON like that: I tried creating models with one-to-one, many-to-one relationships. Controller: But I got I read about creating nodes, but didn’t understand, how integrate it with spring data. What i need to nest table Comments in table Tutorials? Answer Looks to me as if you are pretty close to the desired outcome. First of all
How can I unit-test Exception thrown inside a Lambda?
I have a method: This is how the user authorization test looks like: Is there any way to check the case when a user has entered the wrong password? In the case when I send the wrong password, it doesn’t work because given(this.repository.findByEmail(this.user.getEmail())).willReturn(Optional.of(this.user)); makes repository.findByEmail() return the result before you get to checking the password. Answer You don’t need this
Find date inside each month
In my project, in the repository, this select finds the nearest date with a currency id that is less than or equal to the date whose range I set. How can I find a date in each month that is greater than or equal to the date I want to bind, but with the condition that this date must be
Can’t create one_to_one relationship: Unknown mappedBy in
I try to create an OneToOne relationship between two tables but I receive errors. I used a lot of tutorials but nothing helps. For example baeldung tutorial: Project structure: The error: Gradle: application.properties: Answer You need to use a field name for mappedby, not a column name. In you case, it should be @OneToOne(mappedBy = “personalData”).