Backend Development 18 min read

Comprehensive Spring Boot Integration Guide: Swagger, Redis, MyBatis, Druid, Mail, CORS, AOP and More

This article provides a step‑by‑step tutorial on building a Spring Boot project, covering project generation, core starters, automatic Redis configuration, common annotations like @SpringBootApplication and @ControllerAdvice, web container and HTTPS settings, profile management, CORS, MVC interceptors, AOP, MyBatis‑Druid integration, mail sending, and Swagger API documentation.

Java Architect Essentials
Java Architect Essentials
Java Architect Essentials
Comprehensive Spring Boot Integration Guide: Swagger, Redis, MyBatis, Druid, Mail, CORS, AOP and More

This guide walks through creating a Spring Boot project, starting from generating the skeleton on https://start.spring.io/ , modifying the group and artifact names, downloading, and launching the Application class directly from an IDE such as IDEA.

It explains the concept of Spring Boot starters, emphasizing the "convention over configuration" principle that lets developers avoid manual dependency management. By adding a starter like spring-boot-starter-data-redis , the framework automatically pulls in all required libraries.

For Redis integration, the guide shows the auto‑configuration class RedisAutoConfiguration and how Spring Boot reads properties prefixed with spring.redis to create beans such as RedisTemplate and StringRedisTemplate . Example usage: @Autowired private RedisTemplate redisTemplate; ValueOperations ops = redisTemplate.opsForValue(); Book book = (Book) ops.get("b1");

The composite annotation @SpringBootApplication is broken down into @SpringBootConfiguration , @EnableAutoConfiguration and @ComponentScan , which together bootstrap the application via SpringApplication.run(...) .

Web container configuration examples include setting server port, error path, session timeout, context path, and Tomcat-specific options. HTTPS configuration is demonstrated with properties server.ssl.key-store , server.ssl.key-alias and server.ssl.key-store-password .

Using @ConfigurationProperties , the guide shows how to bind external configuration (e.g., spring.datasource ) to POJOs, with an example Druid datasource bean.

Profile management is covered by using spring.profiles.active in application.properties and programmatically setting additional profiles via SpringApplicationBuilder or command‑line arguments.

Global exception handling and model attributes are illustrated with @ControllerAdvice , @ExceptionHandler , and @ModelAttribute examples, including a custom file‑size‑exceeded handler.

CORS support is enabled by adding @CrossOrigin and setting the Access-Control-Allow-Credentials header in the controller response.

Registering an MVC interceptor is shown with a custom HandlerInterceptor implementation and a WebMvcConfigurer that adds the interceptor to all paths except /hello . The execution order (preHandle → controller → postHandle → afterCompletion) is explained.

AOP activation is as simple as adding the spring-boot-starter-aop dependency.

Integration of MyBatis and Druid is detailed with Maven dependencies, datasource and pool properties, and resource configuration for XML mappers. The guide notes that the starter automatically creates monitoring pages.

Redis integration includes Maven coordinates for spring-boot-starter-data-redis (excluding Lettuce) and jedis , property settings for host, port, and pool, and a REST endpoint that stores and retrieves a Book object.

Mail sending is demonstrated by adding spring-boot-starter-mail and spring-boot-starter-thymeleaf , configuring SMTP (e.g., QQ mail), and using JavaMailSender with a Thymeleaf template to send HTML emails.

Swagger integration is achieved by adding springfox-swagger2 and springfox-swagger-ui dependencies, creating a SwaggerConfig class with API info, and exposing the UI resources.

The article concludes with a brief summary emphasizing that the configurations are basic, encouraging readers to experiment and extend the setup, and provides references to the source material.

integrationbackend developmentRedisSpring BootMyBatisSwaggerMail
Java Architect Essentials
Written by

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.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.