I needed to auto wire logged in User Object in my controller /service classes. So i created a util Bean as and used in controller class as In most controllers it works OK, but in some controllers first logged in user object doesn’t change until I restart the application. my logout configuration is as fo…
Tag: spring-boot
How to read database view metadata
I’m trying to use Java and Spring to read the table structure for a MySQL database. The code I’ve got (based on other answers on this site) is: If I call this code with the name of any of my database tables, it works perfectly. However, when I pass the name of any of my database views, I get the
Spring Boot, OAuth2 authentication is lost between requests
EDIT: log from org.springframework.security: ***But if I look in the logs some requests after I can get the valid auth: Debug 2022-01-17 12:31:03.945 IST “Set SecurityContextHolder to SecurityContextImpl [Authentication=OAuth2AuthenticationToken [Principal=com..security.oauth.CustomOAuth2User@, Credenti…
set class fields based on enum value
Using the above code I can get the value of Tempclass fields based on enum values. Now how to set the fields of Tempclass based on enum value ex: if enum VALUE2 is selected, then i need to set the Tempclass field2 to the input value. Answer Use a BiConsumer<Tempclass, String> taking an instance of TempC…
Database error with Java Spring boot Project
I am trying to run a Java Spring Boot survey project (Maven Architecture) in my local machine by following steps — mvn clean package connect to created jar file java -jar target/filename.jar Open browser and browse to localhost:8080 Project is running ok, I can input survey data, but I am getting follow…
Create RESTful web service for current logged user in Spring Boot
I have URL for user dashboard(/users/{userId}). I wanted to support /users/current for current logged user, and I searched for ways to implement that, and I did that by the following code. However, I think it’s too overwhelming and I wonder if there are better/simpler ways to do that. P. S. I think I ma…
Java JPA SpringBoot
I have table A and table B, table B have a fk that rererences to table A. class EntityA class EntityB But when i try to call findAll method from repository (from EntityA) i get: Could not write JSON: Infinite recursion Answer I’ve solved the problem using unidirectional relationship. Used this on my Ent…
NamedQuery returning entities with null fields
defined entity with namedquery as SELECT mdl FROM tbl_slots mdl where mdl.test_date between :dt and :dt order by mdl.test_time asc if used * instead of mdl in query, JPA gives error unexpected token: * if mentioned the column names in select statement it returns entities with respective fields populated with …
Define Spring dependency matching a Spring Boot version
I am developing two projects. Project 1 is a spring-boot application based on gradle for dependency management. This application defines extension-points. If – at runtime – an extension is found on the classpath, this extension is being called from the main application under certain circumstances.…
Cannot use base class without passing its type in Java
I want to create a common service and common request as shown below: Then implement this service as shown below: However, although CompanyARequest is inherited from CommonRequest, createOrUpdate method throws “Method does not override method from its superclass” error. On the other hand, if I use …