Mall Project Update: SpringBoot 2.3, Elasticsearch 7.6, Unified Swagger & Redis
This article outlines the latest upgrades to the open‑source Mall project, including migration to SpringBoot 2.3.0, support for Elasticsearch 7.6.2, enhanced ELK log collection, unified Swagger and Redis configurations, and updated deployment guides for Windows and Linux environments.
Previously I wrote many articles on mainstream technologies, and friends said they were exactly what they wanted to learn. I plan to apply suitable technologies to my open‑source project. The Mall project has undergone significant upgrades, and this article introduces the changes.
Update Overview
Upgrade to SpringBoot 2.3.0.RELEASE
Support Elasticsearch 7.6.2
Enhanced ELK log collection with scenario‑based logging
Unified Swagger configuration
Unified Redis configuration
Updated deployment documentation for Windows and Linux
Update Details
Upgrade SpringBoot 2.3.0
The project previously used SpringBoot 2.1.7 (released August 2019). SpringBoot 2.3.0, released May this year, brings newer features. See the article "SpringBoot 2.3.0 New Features" for details (https://mp.weixin.qq.com/s?__biz=MzU1Nzg4NjgyMw==∣=2247485932&idx=1&sn=5688aa373fb92b8c73a40254d6ded55e&scene=21#wechat_redirect).
Support Elasticsearch 7.6.2
Because of the SpringBoot upgrade, Elasticsearch was also upgraded to the mainstream 7.x series. The migration involved many pitfalls; see the article "Elasticsearch Upgrade 7.x" for a full account (https://mp.weixin.qq.com/s?__biz=MzU1Nzg4NjgyMw==∣=2247486065&idx=1&sn=3bfcdcc07a66ac47528a752fe9551398&scene=21#wechat_redirect).
ELK Log Collection Improvements
The previous log collection was incomplete and did not use scenario‑based collection. The new system now supports scenario‑based log gathering; refer to the article "Build a Log Collection System" for the setup (https://mp.weixin.qq.com/s?__biz=MzU1Nzg4NjgyMw==∣=2247485508&idx=1&sn=d1d96893a1a3131dd8ef2e8df16d4d02&scene=21#wechat_redirect).
Unified Swagger Configuration
Earlier each module (mall‑admin, mall‑portal, mall‑search) had its own Swagger settings. Now a base configuration BaseSwaggerConfig is added in the mall-common module, providing a swaggerProperties() abstract method for subclasses.
/**
* Swagger base configuration
* Created by macro on 2020/7/16.
*/
public abstract class BaseSwaggerConfig {
@Bean
public Docket createRestApi() {
SwaggerProperties swaggerProperties = swaggerProperties();
Docket docket = new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo(swaggerProperties))
.select()
.apis(RequestHandlerSelectors.basePackage(swaggerProperties.getApiBasePackage()))
.paths(PathSelectors.any())
.build();
if (swaggerProperties.isEnableSecurity()) {
docket.securitySchemes(securitySchemes()).securityContexts(securityContexts());
}
return docket;
}
private ApiInfo apiInfo(SwaggerProperties swaggerProperties) {
return new ApiInfoBuilder()
.title(swaggerProperties.getTitle())
.description(swaggerProperties.getDescription())
.contact(new Contact(swaggerProperties.getContactName(), swaggerProperties.getContactUrl(), swaggerProperties.getContactEmail()))
.version(swaggerProperties.getVersion())
.build();
}
private List<ApiKey> securitySchemes() {
// set request header info
List<ApiKey> result = new ArrayList<>();
ApiKey apiKey = new ApiKey("Authorization", "Authorization", "header");
result.add(apiKey);
return result;
}
private List<SecurityContext> securityContexts() {
// paths requiring authentication
List<SecurityContext> result = new ArrayList<>();
result.add(getContextByPath("/*/.*"));
return result;
}
private SecurityContext getContextByPath(String pathRegex) {
return SecurityContext.builder()
.securityReferences(defaultAuth())
.forPaths(PathSelectors.regex(pathRegex))
.build();
}
private List<SecurityReference> defaultAuth() {
List<SecurityReference> result = new ArrayList<>();
AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything");
AuthorizationScope[] authorizationScopes = new AuthorizationScope[1];
authorizationScopes[0] = authorizationScope;
result.add(new SecurityReference("Authorization", authorizationScopes));
return result;
}
/**
* Custom Swagger configuration
*/
public abstract SwaggerProperties swaggerProperties();
}The custom SwaggerProperties class defines fields such as apiBasePackage, enableSecurity, title, description, version, contactName, contactUrl, and contactEmail.
@Data
@EqualsAndHashCode(callSuper = false)
@Builder
public class SwaggerProperties {
/** API base package */
private String apiBasePackage;
/** Enable login authentication */
private boolean enableSecurity;
/** Document title */
private String title;
/** Document description */
private String description;
/** Document version */
private String version;
/** Contact name */
private String contactName;
/** Contact URL */
private String contactUrl;
/** Contact email */
private String contactEmail;
}Modules such as mall-admin now simply extend BaseSwaggerConfig and provide a SwaggerProperties implementation, e.g.:
@Configuration
@EnableSwagger2
public class SwaggerConfig extends BaseSwaggerConfig {
@Override
public SwaggerProperties swaggerProperties() {
return SwaggerProperties.builder()
.apiBasePackage("com.macro.mall.controller")
.title("mall后台系统")
.description("mall后台相关接口文档")
.contactName("macro")
.version("1.0")
.enableSecurity(true)
.build();
}
}Unified Redis Configuration
Custom Redis settings have been centralized. A base class BaseRedisConfig in the mall-common module provides beans for RedisTemplate, a JSON serializer, a RedisCacheManager with a one‑day TTL, and a RedisService implementation.
/**
* Redis base configuration
* Created by macro on 2020/6/19.
*/
public class BaseRedisConfig {
@Bean
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
RedisSerializer<Object> serializer = redisSerializer();
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
redisTemplate.setConnectionFactory(redisConnectionFactory);
redisTemplate.setKeySerializer(new StringRedisSerializer());
redisTemplate.setValueSerializer(serializer);
redisTemplate.setHashKeySerializer(new StringRedisSerializer());
redisTemplate.setHashValueSerializer(serializer);
redisTemplate.afterPropertiesSet();
return redisTemplate;
}
@Bean
public RedisSerializer<Object> redisSerializer() {
// create JSON serializer
Jackson2JsonRedisSerializer<Object> serializer = new Jackson2JsonRedisSerializer<>(Object.class);
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
// must enable default typing
objectMapper.activateDefaultTyping(LaissezFaireSubTypeValidator.instance, ObjectMapper.DefaultTyping.NON_FINAL);
serializer.setObjectMapper(objectMapper);
return serializer;
}
@Bean
public RedisCacheManager redisCacheManager(RedisConnectionFactory redisConnectionFactory) {
RedisCacheWriter redisCacheWriter = RedisCacheWriter.nonLockingRedisCacheWriter(redisConnectionFactory);
// set cache TTL to 1 day
RedisCacheConfiguration redisCacheConfiguration = RedisCacheConfiguration.defaultCacheConfig()
.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(redisSerializer()))
.entryTtl(Duration.ofDays(1));
return new RedisCacheManager(redisCacheWriter, redisCacheConfiguration);
}
@Bean
public RedisService redisService() {
return new RedisServiceImpl();
}
}Other modules, such as mall-security, can simply extend this configuration and inject RedisService to operate on Redis.
Updated Deployment Documentation
The deployment guides have been refreshed for three scenarios: Windows, Docker container on Linux, and Docker Compose on Linux, each with a dedicated URL.
Project Repository
GitHub: https://github.com/macrozheng/mall
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
macrozheng
Dedicated to Java tech sharing and dissecting top open-source projects. Topics include Spring Boot, Spring Cloud, Docker, Kubernetes and more. Author’s GitHub project “mall” has 50K+ stars.
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.
