There’s this weird problem. I’m currently testing two repository classes that I plan to use as MockBean. The snippets of the code are as follows: For ClassARepoHibernate For ClassBRepoHibernate Now then, on the testing class, I put this up: When I run this test, it gives out this error before even going to the breakpoint if I debug: This confuses
Tag: spring
stream is closed and Could not find acceptable representation error
i’m consuming a Api witch is returning pdf as ResponseEntity but it is not working at my api i’m trying to get de file coming from the external api and provide it at my endpoint. # External Api FeignClient class My service method my endpoint and stackTrace enter image description here i’m trying to get de file coming from the
How to inject/pass value into @Configuration-bean after/in application.run() method?
My application in main method reads parameters and runs Spring application. My Configuration with DataSource bean inside needs to read one of the parameter to use in initialization of datasource. Application class Configuration class So I need my DataSource getDataSource() to properly read that credentialsPropertyPrefix argument and use in datasource. Answer Try
Paketo BuildPacks Java JSON Log for Spring Boot Application
We are using Paketo BuildPacks for our Spring Boot application. We configured all logs to be JSON written to STDOUT. The issue is that there’s a few lines of logs by Paketo during startup: Is there any way to configure Paketo to print the above as JSON: Answer No, sorry. The logging format in Paketo Buildpacks, and the helpers (technical
Why does Spring Security 6 not create sessions when authenticating with curl and basic auth?
I recently upgraded to Spring Security 6, and have found that authenticating using basic auth from JS or from curl no longer works but authenticating with basic auth using Java’s HttpClient does work. My goal is to be able to authenticate with all approaches. The app uses Java 17, Spring Security 6, and Spring Session 3. It has a “login”
How to convert String to UTC timezone?
I have a string like this, I have a utility which converts this string to UTC time This returns the result 2022-12-09T12:21:32Z It gives back the time difference of 4 hours. Shouldn’t it be 5 hours? Answer There is a time change in EST timezone on October 30th, try in September and you have only 4 hours difference and 5
Mocking a Nested Object in Junit
I have a service I am mocking like this: } the service: I need to be able to mock the “CloseableHttpResponse response = httpclient.execute(request, clientContext)”, such that the “response” object is something I create ahead of time. I am hoping some mocking when/then constructs would work for this? I would grateful for ideas on how to do this. Thanks! Answer
I am trying to create an API using SpringBoot but I don’t know how to handle json request/response
I am new to Java and Spring boot. I am creating a new API. Using postman I am sending a request body which contains request header and request payload. Then I have a controller which handles the request with the help of RequestPayload class. (And a service and dao file but I am sure those are ok.) Kindly let me
Isn’t SecurityContextHolder a Bean?
Trying to Autowire SecurityContextHolder I get error Turns out that it is available from any part of the code like How come it isn’t a bean and how does it get initialized under the hood? Are there other static utility classes like that available to be consumed from anywhere and how do I find them? Answer SecurityContextHolder is a utility
Is the Jackson2JsonMessageConverter class thread-safe?
I’m using this class and I’m wondering whether it’s thread safe: https://docs.spring.io/spring-amqp/api/org/springframework/amqp/support/converter/Jackson2JsonMessageConverter.html The docs don’t make any claims about this. I skipped through the code and found no signs it’s not thread-safe. It’s using an ObjectMapper internally, which is thread-safe according to docs: https://fasterxml.github.io/jackson-databind/javadoc/2.13/com/fasterxml/jackson/databind/ObjectMapper.html Mapper instances are fully thread-safe provided that ALL configuration of the instance occurs before ANY read