I need to need to get customized JSON object rather than default one in Spring Boot. I could successfully get default response but I need to customize as below. Some objects needed to be converted to array and some fields should be removed. Actual Response Expected Response Changes Service Class Implementatio…
Tag: spring-boot
Spring Webflux – Proper way to throw checked custom exception (not RuntimeException)
May I ask what is the proper way to throw checked custom exception in Spring webflux please? I would like to insist, it is about checked custom exception, like MyException.java, not something like RuntimeException, and it is about throwing exception, not handling exception. I tried the following : This is not…
when there are some classes which may not exist, how should I manage them in an XxxAutoConfiguration?
com.example A // it provide AFactory.class 1 …
Spring MVC – Separation of logic RestController and Service
I started using Spring MVC to build my first REST API 🙂 Now I struggle a bit of where to put which logic. I read the following: @RestController: Handles requests, defines the API the user can use @Service: Contains the business logic @Repository: Abstracts away from access to DB In an easy first example, I sa…
SpringBoot ignoring my @RequestBody param?
I have the following Controller: The ProductCost model looks like: My problem is that when calling that endpoint, the productCost variable comes with all fields set to null, even though I’m seding it real data. The request body looks like: Am I missing something obvious? Why is the Product Cost not mapp…
Concurrent requests transaction to prevent unwanted persistence
I am trying to get my head around how to approach what initially seems a “simple” problem. I have UserAccounts that can have MANY Purcahses BUT business logic dictates can only have one Purchase in a PurchaseState.IDLE state (a field on the entity). A purchase is IDLE when first created. I have a …
Spring Boot 2.x Servlet Path is ignored in test
in my application-test.properties I have this server.servlet.context-path=/api It works totally fine when I run the application and test it with postman. But as soon as I run my tests it swallows the part /api of the path. So basically how it should be localhost:8080/api/testUrl but the controller is only ava…
RestTemplate logging interceptor + Spring Cloud Sleuth
I’ve created a RestTemplate interceptor (ClientHttpRequestInterceptor) to log requests and responses and enabled Spring Cloud Sleuth with the goal of tracing transactions from when the interceptor receives a request to the point where it returns a result. However, Sleuth’s trace and span ids do no…
Java file outside of source root intelliJ
I have cloned a spring boot project from GitLab having multiple branches in IntelliJ. I checkout to the branch in which I want to work. But I am getting “Java file outside of source root” on all the files. Please suggest what I am doing wrong. I just installed IntelliJ and it’s the first pro…
What’s the effective way to insert more a million rows into postgresql server from another postgres server using Java?
I have two postgresql servers and I need to copy table rows with from first server format and convert to another server format (different column names). I use java application with spring boot and jpa repository, which implemented method findAll with stream read fetch size 1000. After reading I convert and in…