Stack: Spring Security and Thymeleaf. I have the following problem: I want to show or not show some elements in all html templates depending on user’s role. So, I need a boolean variable “isAdmin” in all templates so that I can use it in conditions: Please help me find the best solution. What I tried: Option 1. I can add
Tag: spring
Spring @Transactional with base and subclasses
I am confused about @Transactional annotation with base and subclasses. I have the following code with several generic subclasses derived from the base class CustomRepository<T> which implements ICustomRepository<T>. I want all the methods of the interface ICustomRepository<T> be transactional. Is it enough to put @Transactional just in the base class so that the call findAll() from sublasses also become transactional.
When is a @JsonCreator method required for parsing?
When I try to parse the following object: I get the error And I solved this by adding a creator to the User class like this: This works fine. So now I go and parse the following object: and I don’t get an error… why? why it doesn’t require me to use a constructor here? Here’s the class where the
How to replace an old ibm mq batch V7
I’m wondering what is the best way to replace and old ibm batch java application: In fact , I have a java application which contains basically two classes and can be started using two shell files; a shell to send and message and another one to consume messages present in the Queue. sendMessage.ksh => start the application and calls send
How to access configuration beans in Spring controllers
I have a Spring Boot application that uses Spring profiles to create environment specific configurations, for example: I have a @RestContoller that needs to access the values that the configurations load from application.properties. How can I inject the current environment specific configuration bean inside the controller? Example: Answer If you need to access values from the application.properties or .yaml configuration
Data type is not updating on Database
In my entity class, I want to change the data type of a field but it’s not updating in the database. I am using PostgreSQL. I have also tried adding this: in application properties and still, it doesn’t work I don’t know why, please help, and thanks. What I have : Answer If you just created your database and doesn’t
delete where all keys of a map are contained in a list in mongodb
I have this: A field which is a map where the keys are UUIDs and the value another object which is not relevant. A list of UUIDs that should be passed as parameter. I want to: delete from the collection all documents where all keys of the map are included in the list of UUIDs The object: With derived queries
are there any pitfalls when return @Entity from @RestController instead of DTO?
are there any pitfalls when return @Entity from @RestController instead of DTO ? like this: Answer I’d say yes. By returning an entity, you are going to have tight coupling of your response contract and the database entity. So in future if you want to make modifications to either your response/entity, you might run into multiple issues. For example, let’s
Is CSRF token require for Rest API in Spring boot
I am creating a Rest API using Spring boot on back-end and React js on frontend . I have a login form on React , should I enable csrf token on login/register form or not . After user logs in that user will get access token which I will store in memory in React and Refresh token in http only
How to not hardcoding image extensions in Java?
How to not hardcoding image extensions in Java? Above is my code. In the case statement, I have listed strings as hard-coded as jpg, jpeg…. This code is not flexible, so I’m sure there must be a better way. I’d appreciate it if you could give me a solution that I’m not aware of. Answer As one of possible ways,