I’m having problems parsing JSON, this is the error: And I know why it is happening I just don’t know how to fix it. This JSON works: This one does not: The problem seems to be the { character in front of the info field because with [ works. So this is the method I’m using to parse the JSON:
Tag: spring-boot
How to ignore a method call inside a method that is being tested?
I am trying to make a test pass with mockmvc and it is failing with the following error message: Caused by: org.apache.kafka.common.config.ConfigException We have Kafka in our service layer as a dependency, and it is being called inside the method we are testing. Is there a way to ignore that specific call during tests? In the example below, we want
Cannot invoke findByEmail because “this.userRepository” is null error
I keep receiving a Cannot invoke “com.***.repositories.UserRepository.findByEmail(String)” because “this.userRepository” is null error everytime I try to process my /register method. I can’t figure out why the code is coming across as null. Controller – Axios call – My UserRepository – Answer Simply add @Autowired to your related fields you want to get Autowired by spring. Change your code from to
How to use @ConfigurationProperties with Records?
Java 16 introduced Records, which help to reduce boilerplate code when writing classes that carry immutable data. When I try to use a Record as @ConfigurationProperties bean as follows I get the following error message: How can I use Records as @ConfigurationProperties? Answer Answering my own question. The above error raises from Spring Boot not being able to construct the
Mapstruct: Returning null when trying to map a field inside an embedded object
We were given an assignment to recreate a simple version of the Twitter API in Spring using Mapstruct. We are returning a List<UserDto> that should return the field username from the embedded object Credentials. We mapped this as follows: Our UserDto is specified like this: Our User entity has an embedded object named credentials, where the username and password of
JPA and Hibernate, OneToMany relationship with a composite key using UUID
I’m using SpringBoot with JPA and Hibernate. I have two entities: Book and Author. A Book can have multiple Authors. So I need a OneToMany relationship. Into the Author table, my idea is to use a composite key (the book_id and one internal field for example field_a) I implemented these classes: When I try to execute my project (I’m using
Publishing Spring Batch metrics using Micrometer
I have an app that contains 2 dozen of spring batch cron jobs.There is no rest controller as it is an analytics app and it runs daily and read data from db, process it, and then store aggregated data in another db.I want to have spring inbuilt metrics on the jobs using micrometer and push them to Prometheus .As my
How to log the number of available/used threads in a spring boot (tomcat) based application?
Is there a spring boot config where you can log the number of available/used threads the app server currently has? Answer You can use the actuator framework. Then you have to enable tomcat JXM metrics in application.properties and expose the metrics endpoint The go to http://localhost:8080/actuator/metrics/ and you will see all the available metrics. For example current threads http://localhost:8080/actuator/metrics/tomcat.threads.current
Spring Boot Log4j2 configuration issue with log size maintenance
I have a spring boot application and using log4j2 to generate console and persists logs in a centos linux. I wanted to maintain only 5mb of log files in archive. But the problem is, my archived log files are 5mb in total. but my main console log which is saving in the main log file i.e wc-notification.out is going beyond
Problems with launch spring boot jar on ubuntu server. Error starting ApplicationContext
I have configured nginx to fit my code. My code works well on Windows and now I’m trying to deploy it to Ubuntu. I run jar and it fail. Logs: My propeties: continues code: upload.path=home/kirill/uploads #properties for MailSender #smptps – Not secure connection spring.mail.host=smtp.yandex.ru #test spring.mail.username= HIDED EMAIL spring.mail.password=password spring.mail.port=465 spring.mail.protocol=smtps mail.debug=false recaptcha.secret=hided secret spring.session.jdbc.initialize-schema=always spring.session.jdbc.table-name=SPRING_SESSION hostname= HIDED HOST server.port=80