Loading...

Questions tagged [spring-boot]

Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications.

11 questions with this tag
18
votes
1
answers
Spring Data JPA Repository returns null instead of empty list

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 inte...

asked by jpa_wizard 2 days ago
29
votes
2
answers
How to write unit tests for Spring Boot controllers with WebMvcTest?

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....

asked by micro_king 3 days ago
45
votes
3
answers
What is the difference between Spring and Spring Boot?

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 i...

asked by spring_guru 3 days ago
44
votes
2
answers
Best way to handle exceptions globally in Spring Boot REST API?

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 pra...

asked by java_master 4 days ago
32
votes
2
answers
How do I enable and secure Spring Boot Actuator endpoints?

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...

asked by boot_dev 4 days ago
41
votes
2
answers
How to validate request body in Spring Boot REST API?

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; p...

asked by java_master 5 days ago
27
votes
2
answers
How to use Spring Boot profiles for different environments?

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 ...

asked by micro_king 6 days ago
56
votes
3
answers
LazyInitializationException in Spring Boot JPA - How to fix?

I'm getting this error when trying to access a collection after fetching an entity: ``` org.hibernate.LazyInitializationException: failed to lazily i...

asked by jpa_wizard 6 days ago
52
votes
3
answers
How to enable CORS in Spring Boot for my React frontend?

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: ``` Ac...

asked by spring_guru 1 week ago
67
votes
4
answers
@Autowired vs Constructor Injection - which is better in Spring Boot?

I've seen two ways to inject dependencies in Spring Boot: ```java // Field Injection @Autowired private UserService userService; // Constructor Inje...

asked by boot_dev 1 week ago