I have a spring MVC project that I have develop for my team at work. I have an endpoint that create a workbook using apache poi, then export to .xlsx file, but my code appeared to write to file on the application host instead of user’s computer. I know I’m missing something, but I try what I found…
Tag: spring
Image and PDF files getting corrupted while uploading on AWS S3
I am trying to upload images and PDF on AWS S3 using my Spring Boot app. They are getting uploaded in corrupt format without any error. Text files are uploaded successfully. Below is the dependencies we have used. Answer My code works fine. The issue was in the AWS API Gateway. We need to add ‘*/*’…
MessageDigest NoSuchAlgorithmException in Java
So, I’ve cruised through several Stackoverflow threads and other websites as well whilst trying to find a solution to this. I am working on a school assignment that requires the use of an instance of …
Spring Boot – Host JaCoCo coverage as static HTML
I am working with Spring Boot 2.2.5 and Java 8. I have a Spring Boot webservice that I deploy and run as a linux service using the embedded Tomcat in Spring Boot. During my Maven build, I generate code coverage metrics using the JaCoCo Maven plugin, and I would like to package and host these static HTML pages…
How validate an object using @Valid in Spring Boot?
I’m working on a Spring Boot project and I’m trying to validate some fields from an object. Actually I have an API which accepts parameters. I know I can use @Valid into API declaration like this: But I don’t want to validate there. I have a “filter” object to validate the values…
Spring Boot HttpSecurity – @PreAuthorize – How to set AuthenticationFilter?
I am currently developing a API Authorization. So basically I have a filter JwtAuthorizationFilter. And in my RestController I want to annotate the request that should be filtered via @PreAuthorize(“hasRole(‘ADMIN’)”) for example. So my question is now: How do i have to setup the WebSe…
How to handle Kafka container lifecycle using spring kafka in Kubernetes multipod deployment
I am using Spring kafka implementation and I need to start and stop my kafka consumer through an REST API. For that i am using KafkaListenerEndpointRegistry endpointRegistry endpointRegistry.getListenerContainer(“consumer1”).stop(); endpointRegistry.getListenerContainer(“consumer1”).st…
Spring Data JPA – Get all elements
I’m new to Spring Data JPA and I want to ask if there is a method that can be used to fetch all items, not by a certain criterion. Any help would be helpful. Answer Use the findAll method from repository Take a look here Spring Data JPA API Look here a small example that will fetch all MyObj objects
Spring ControllerAdvice does not return response body?
I have the following ControllerAdvice, that handles JsonParseException (I use Spring and Jackson) Fore some reason, It doesn’t work when I send a bad json request to the server, only returns 400. When I change the HttpStatus, it still returns 400 so it seems like the advice doesn’t really run. Ans…
Configure Spring Boot’s with custom SSLContext programmatically (for mTLS)
Problem Programmatically configure Spring Boot’s to use my custom SSLContext. And use for mTLS. Context Spring’s documentation provides only one, clear way how to configure SSL (via application.properties): However, this solution lacks depth as there are scenarios, where I’d like to advantag…