I have a JPA Repository method that should return a List, but it returns null instead of an empty list when no results are found. ```java public interface UserRepository extends JpaRepository { L...
I want to write unit tests for my REST controllers in Spring Boot. I've heard about @WebMvcTest but I'm not sure how to use it properly. How do I: 1. Test controller methods in isolation 2. Mock serv...
I am new to Java development and I keep hearing about Spring and Spring Boot. What exactly is the difference between them? I understand that Spring is a framework, but what does Spring Boot add on to...
I want to handle all exceptions in one place in my Spring Boot application instead of using try-catch in every controller method. What's the best practice for global exception handling that returns p...
I want to use Spring Boot Actuator to monitor my application in production. I added the dependency but all endpoints are exposed. How do I: 1. Enable only specific endpoints (health, info, metrics) 2...
I'm building a REST API and need to validate the request body. I have a UserDTO class: ```java public class UserDTO { private String email; private String name; private Integer age; } ```...
I need to configure different database settings for dev, test, and production environments in my Spring Boot application. What's the best way to use profiles? Should I use separate YAML files or prof...
I'm getting this error when trying to access a collection after fetching an entity: ``` org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.example.User.p...
I have a Spring Boot backend running on localhost:8080 and a React frontend on localhost:3000. When I try to make API calls from React, I get: ``` Access to XMLHttpRequest has been blocked by CORS po...
I've seen two ways to inject dependencies in Spring Boot: ```java // Field Injection @Autowired private UserService userService; // Constructor Injection private final UserService userService; publ...