Spring Boot Project Initialization, Version Management, and Common Scaffold Code Guide
This article walks through initializing a Spring Boot project, handling version compatibility between Spring Cloud, Spring Boot, and Kafka, demonstrates common scaffolding code such as global exception handling, logging, CORS configuration, and recommends useful tools like Maven, embedded Redis, MyBatis‑Plus, and MapStruct for backend development.
In this tutorial the author, a Java architect, shares the steps to create a new Spring Boot project, the challenges of environment setup, and how to use IDEs and community editions.
1. Project Initialization
After downloading an IDE (e.g., IntelliJ IDEA) the author creates a Spring Boot project, showing the generated main class, configuration file and test class.
2. Version Management
The compatibility between Spring Cloud, Spring Boot and Kafka versions is illustrated, with links to the official version tables.
https://spring.io/projects/spring-cloud
https://spring.io/projects/spring-kafka
A real‑world mismatch example is described where the production Kafka broker (0.11) does not support the client version (3.0.4), leading to an UnsupportedVersionException .
3. Scaffold Code
Common utility classes are provided, including a global exception handler, a logging aspect, CORS configuration, Swagger configuration, and a generic response wrapper.
@RestControllerAdvice
@ResponseBody
@Slf4j
public class GlobalExceptionHandler {
@ExceptionHandler(value = {MethodArgumentNotValidException.class})
public ResponseResult
handleValidException(MethodArgumentNotValidException ex, HttpServletResponse httpServletResponse) {
log.error("[GlobalExceptionHandler][handleValidException] 参数校验exception", ex);
return wrapperBindingResult(ex.getBindingResult(), httpServletResponse);
}
// ... other methods ...
} @Aspect
@Slf4j
@Component
public class WebLogAspect {
@Pointcut("@within(org.springframework.stereotype.Controller) || @within(org.springframework.web.bind.annotation.RestController)")
public void cutController() {}
@Before("cutController()")
public void doBefore(JoinPoint point) {
// log request details
}
@AfterReturning(returning = "response", pointcut = "cutController()")
public void doAfterReturning(Object response) {
if (response != null) {
log.info("请求返回result:[{}]", JSONUtil.toJsonStr(response));
}
}
}Additional helper classes for CORS, Swagger, and a generic ResponseResult wrapper are also shown.
Summary
The article emphasizes that while IDE setup can be tedious, version mismatches and missing scaffolding code often consume more time, and recommends using tools such as Maven, embedded Redis, embedded databases, MyBatis‑Plus, Hutool, MapStruct, and Redisson to streamline development.
Java Architect Essentials
Committed to sharing quality articles and tutorials to help Java programmers progress from junior to mid-level to senior architect. We curate high-quality learning resources, interview questions, videos, and projects from across the internet to help you systematically improve your Java architecture skills. Follow and reply '1024' to get Java programming resources. Learn together, grow together.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.