Model answers for 4 Spring Boot questions
Typical round: Spring core, JPA, a microservice scenario
Q: How does auto-configuration work? A: @SpringBootApplication enables auto-configuration, which loads configuration classes listed by the starters on the classpath. Each uses conditions like @ConditionalOnClass and @ConditionalOnMissingBean, so it configures defaults only when you haven't defined your own bean.
Q: Why might @Transactional not work? A: Spring applies it through a proxy, so it is ignored on private methods and on self-invocation from another method in the same class. By default it also rolls back only for unchecked exceptions unless rollbackFor is set.
Q: What is the N+1 problem in JPA? A: Loading a list of parents and then lazily loading each child collection triggers one query plus N more. Fix it with a JOIN FETCH query, an entity graph, or batch fetching.
Q: How do you handle exceptions in a REST API? A: Throw meaningful custom exceptions and map them in a @RestControllerAdvice with @ExceptionHandler methods that return consistent error bodies and correct HTTP status codes.