Unlock 10 Powerful Spring Boot 3 Starters: Real‑World Cases & Code
This article introduces ten practical Spring Boot 3 starter libraries—ShedLock, p6spy, Logbook, Jasypt, Bucket4j, gRPC, Retrofit, MapStruct‑Plus, Redisson, and Resilience4j—detailing their purpose, Maven coordinates, configuration snippets, core usage code, and links to official documentation, helping developers quickly enhance performance, security, and reliability in backend projects.
Introduction
Developers often encounter performance bottlenecks and security issues in high‑concurrency scenarios. The Spring Boot ecosystem provides a rich set of open‑source starter components that address these pain points, allowing developers to focus on core business logic.
Practical Cases
2.1 ShedLock
ShedLock guarantees that a scheduled task runs only once across a cluster by acquiring a lock in external storage such as Mongo, JDBC, Redis, Hazelcast, or ZooKeeper.
Dependency coordinates
<dependency>
<groupId>net.javacrumbs.shedlock</groupId>
<artifactId>shedlock-spring</artifactId>
<version>6.9.2</version>
</dependency>
<!-- Redis provider -->
<dependency>
<groupId>net.javacrumbs.shedlock</groupId>
<artifactId>shedlock-provider-redis-spring</artifactId>
<version>6.9.2</version>
</dependency>Basic usage
@Configuration
@EnableScheduling
@EnableSchedulerLock(defaultLockAtMostFor = "10m")
public class AppConfig {
@Bean
LockProvider redisLockProvider(RedisConnectionFactory factory) {
return new RedisLockProvider(factory);
}
@Scheduled(...)
@SchedulerLock(name = "scheduledTaskName")
public void scheduledTask() {
// TODO
}
}Official repository: https://github.com/lukas-krecan/ShedLock
2.2 p6spy
p6spy intercepts and logs all JDBC statements without modifying existing code, providing a convenient way to monitor database interactions.
Dependency coordinates
<dependency>
<groupId>com.github.gavlyukovskiy</groupId>
<artifactId>p6spy-spring-boot-starter</artifactId>
<version>1.11.0</version>
</dependency>Configuration (application.yml)
decorator:
datasource:
p6spy:
enable-logging: true
logging: slf4jSample log output (image):
Official repository: https://github.com/gavlyukovskiy/spring-boot-data-source-decorator
2.3 Logbook
Logbook is an extensible Java library that logs HTTP requests and responses, making it easy to persist and analyze traffic for auditing or debugging.
Dependency coordinates
<dependency>
<groupId>org.zalando</groupId>
<artifactId>logbook-spring-boot-starter</artifactId>
<version>3.12.2</version>
</dependency>Configuration (application.yml)
logging:
level:
'[org.zalando.logbook.Logbook]': TRACECustom bean example:
@Bean
public Logbook logbook() {
return Logbook.builder()
.condition(Conditions.exclude(
Conditions.requestTo("/api/query"),
Conditions.contentType("application/octet-stream"),
Conditions.header("X-Secret", "true")))
.sink(new DefaultSink(new DefaultHttpLogFormatter(), new DefaultHttpLogWriter()))
.build();
}Official repository: https://github.com/zalando/logbook
2.4 Jasypt
Jasypt Spring Boot adds encryption support for Spring Boot property sources, allowing sensitive configuration values to be stored securely.
Dependency coordinates
<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId>
<version>3.0.5</version>
</dependency>Basic usage
// Encrypt a value
java org.jasypt.intf.cli.JasyptPBEStringEncryptionCLI \
input="xxxooo" password="aaaabbbbcccc6666" algorithm="PBEWithMD5AndDES"Encrypted value can be used in application.yml:
spring:
datasource:
password: ENC(x8hoXK78YcyblFzV3vohDA==)Run the application with the encryption password:
java -jar app.jar --jasypt.encryptor.password=aaaabbbbcccc6666Official repository: https://github.com/ulisesbocchio/jasypt-spring-boot
2.5 Bucket4j
Bucket4j implements the token‑bucket algorithm for rate limiting, supporting both in‑memory and distributed caches via JCache.
Dependency coordinates
<dependency>
<groupId>com.giffing.bucket4j.spring.boot.starter</groupId>
<artifactId>bucket4j-spring-boot-starter</artifactId>
<version>0.12.10</version>
</dependency>
<dependency>
<groupId>com.bucket4j</groupId>
<artifactId>bucket4j-redis</artifactId>
<version>8.10.1</version>
</dependency>Configuration (application.yml)
bucket4j:
cache-to-use: redis-lettuce
filters:
- filter-method: webflux
cache-name: product-cache
id: product_filter
url: /products/.*
rate-limits:
- cache-key: getParameter("id")
bandwidths:
- capacity: 2
time: 30
unit: seconds
refill-speed: intervalExample Redis client bean:
@Bean
RedisClient redisClient() {
RedisURI redisURI = RedisURI.create("localhost", 6379);
redisURI.setDatabase(6);
redisURI.setCredentialsProvider(new RedisCredentialsProvider() {
@Override
public Mono<RedisCredentials> resolveCredentials() {
return Mono.just(RedisCredentials.just(null, "123123"));
}
});
return RedisClient.create(redisURI);
}Sample request result (image):
2.6 gRPC
grpc‑spring‑boot‑starter integrates Google’s high‑performance RPC framework with Spring Boot, simplifying server and client setup.
Dependency coordinates
<dependency>
<groupId>net.devh</groupId>
<artifactId>grpc-spring-boot-starter</artifactId>
<version>3.1.0.RELEASE</version>
</dependency>Configuration (application.yml)
grpc:
client:
GLOBAL:
address: localhost:7777
negotiation-type: plaintext
server:
port: 7777Official documentation: https://grpc-ecosystem.github.io/grpc-spring/zh-CN/
2.7 Retrofit
retrofit‑spring‑boot‑starter provides a type‑safe HTTP client for Java and Android, enabling quick integration of REST services.
Dependency coordinates
<dependency>
<groupId>com.github.lianjiatech</groupId>
<artifactId>retrofit-spring-boot-starter</artifactId>
<version>3.1.7</version>
</dependency>Define an interface
@RetrofitClient(baseUrl = "${test.baseUrl}")
public interface UserService {
/** Get user name by id */
@POST("getName")
String getName(@Query("id") Long id);
}Inject and use:
@Service
public class BusinessService {
private final UserService userService;
public BusinessService(UserService userService) {
this.userService = userService;
}
public void doBusiness() {
// call userService
}
}Official repository: https://github.com/LianjiaTech/retrofit-spring-boot-starter
2.8 MapStruct‑Plus
MapStruct‑Plus extends MapStruct with additional features, automatically generating conversion code between Java types.
Dependency coordinates
<dependency>
<groupId>io.github.linpeilie</groupId>
<artifactId>mapstruct-plus-spring-boot-starter</artifactId>
<version>1.4.8</version>
<scope>runtime</scope>
</dependency>Basic usage
@AutoMapper(target = UserDto.class)
public class User {
private String name;
private Integer age;
}
public class UserDto {
private String name;
private Integer age;
}Generated mapper can be used in tests:
@Resource
private Converter converter;
@Test
public void test() {
User user = new User();
user.setName("jack");
user.setAge(23);
UserDto userDto = converter.convert(user, UserDto.class);
System.out.println(userDto);
}Official repository: https://github.com/linpeilie/mapstruct-plus
2.9 Redisson
Redisson provides a Java client for Redis/Valkey with distributed data structures and utilities, including distributed locks.
Dependency coordinates
<dependency>
<groupId>org.redisson</groupId>
<artifactId>redisson-spring-boot-starter</artifactId>
<version>3.50.0</version>
</dependency>Distributed lock example
RLock lock = redisson.getLock("myLock");
// Simple lock
lock.lock();
// Auto‑unlock after 10 seconds
lock.lock(10, TimeUnit.SECONDS);
// Try lock with wait time and lease time
boolean acquired = lock.tryLock(100, 10, TimeUnit.SECONDS);
if (acquired) {
try {
// critical section
} finally {
lock.unlock();
}
}Official repository: https://github.com/redisson/redisson?tab=readme-ov-file
2.10 Resilience4j
Resilience4j is a lightweight fault‑tolerance library designed for functional programming, offering circuit breakers, rate limiters, retries, and bulkheads.
Dependency coordinates
<dependency>
<groupId>io.github.resilience4j</groupId>
<artifactId>resilience4j-spring-boot3</artifactId>
<version>2.3.0</version>
</dependency>Configuration (application.yml)
resilience4j:
circuitbreaker:
configs:
userCfg:
minimum-number-of-calls: 2
wait-duration-in-open-state: 10s
instances:
userList:
base-config: userCfgBusiness code example
private final CircuitBreakerRegistry circuitBreakerRegistry;
public UserService(CircuitBreakerRegistry circuitBreakerRegistry) {
this.circuitBreakerRegistry = circuitBreakerRegistry;
}
@CircuitBreaker(name = "userList", fallbackMethod = "findAllFallback")
public List<User> findAll() {
System.out.println(1 / 0); // trigger exception
try { TimeUnit.MILLISECONDS.sleep(2000); } catch (InterruptedException e) {}
return List.of(
new User(1L, "Pack", 20),
new User(2L, "Jack", 22),
new User(3L, "Wake", 24),
new User(4L, "Caoo", 26)
);
}
public List<User> findAllFallback(Throwable ex) {
System.err.printf("Exception: %s%n", ex.getMessage());
return List.of();
}Official documentation: https://resilience4j.readme.io/docs/getting-started
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.
Spring Full-Stack Practical Cases
Full-stack Java development with Vue 2/3 front-end suite; hands-on examples and source code analysis for Spring, Spring Boot 2/3, and Spring Cloud.
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.
