I’m trying to make a working demo using Spring Boot as a Resource Server and Keycloak as an Authorization Server. Here is project code snippets: pom.xml App.java AppRestController.java application.properties I’m running Keycloak on the port 8083. Get request to the http://localhost:8083/realms/rea…
Tag: spring-boot
Is there a better way to write my if statement?
I have a function that checks if multiple conditions are fulfilled before performing an operation. The code below shows all conditions that must be fulfilled. This code works perfectly as is. However, is there a better way of writing my if statements? Something about the look of it just feels wrong, feels ver…
JPA integrity constraint violated – parent key not found when trying to save entity with JoinColumn
I am trying to save a User Entity with Roles under it. It seems like since the roles do not have their user id foreign key set it fails to save, is there a way to tell jpa to set the role’s user id after it saves the user but before it saves the user’s roles? Or will I need
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 @Sch…
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…
Spring boot “no transaction is in progress” with 2 datasources
I have two databases and i’m trying to save some records to both of them inside a service method. This gives me the error: org.springframework.dao.InvalidDataAccessApiUsageException: no transaction is in progress; nested exception is javax.persistence.TransactionRequiredException: no transaction is in p…
Hikari CP DB connection not release in Async block
I am using Spring Boot application which has API controller to generate reports . The actual service function is wrapped around @Async annotation and function makes DB calls and generates the csv reports . I am also using Hikari CP for connection pool management and JPA + QueryDSL for forming select queries .…
How to get jobId with @BeforeStep in spring batch with compositeItem processor?
I have a composite item processor like so: I am not able to get jobExecutionId in any of the process with @Beforestep This is processor 1. This is processor 2. Here is my job configuration. I am using a listener for skipped user records. With this configuration, I am not abled to get the jobExecutionId in any…
Is there any pitfall using mutable set when mapping two repositories by using @OneToMany
I have two repositories mapped by using @OneToMany notation. Let’s say @OneToMany entity is A, and @ManyToOne entity is B. I keep mutableSetOf(B) in entity of A. After I map two of them I had to get first B after checking some properties. But while debugging I realized that order of them comes randomly …
JOOQ – Codegen – How to generate DAOs and POJOs into two differents Maven module
I use JOOQ with a PostgreSQL database. For the moment all the code generated by JOOQ is in the same Maven project. I would like to know if it is possible to separate the JOOQ code generation in two separate Maven modules: in a server module: JOOQ records and DAOs generation in a common module: generation of P…