### Spring Boot 4.0 Upgrade Example
Source: https://context7.com/openrewrite/rewrite-spring/llms.txt
Shows starter dependency renames for migrating to Spring Boot 4.0, such as webmvc and security-oauth2-client.
```xml
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-starter-oauth2-client
org.springframework.boot
spring-boot-starter-webmvc
4.0.x
org.springframework.boot
spring-boot-starter-security-oauth2-client
4.0.x
```
--------------------------------
### Spring Boot 3.5 Upgrade Example
Source: https://context7.com/openrewrite/rewrite-spring/llms.txt
Illustrates the dependency changes for migrating to Spring Boot 3.5, specifically the Prometheus Pushgateway artifact rename.
```xml
org.springframework.boot
spring-boot-starter-parent
3.3.4
io.prometheus
simpleclient_pushgateway
org.springframework.boot
spring-boot-starter-parent
3.5.x
io.prometheus
prometheus-metrics-exporter-pushgateway
```
--------------------------------
### Run OpenRewrite Gradle Plugin
Source: https://context7.com/openrewrite/rewrite-spring/llms.txt
Use ./gradlew rewriteRun to apply changes or ./gradlew rewriteDryRun to preview changes.
```bash
./gradlew rewriteRun
```
```bash
./gradlew rewriteDryRun
```
--------------------------------
### Run OpenRewrite Maven Plugin
Source: https://context7.com/openrewrite/rewrite-spring/llms.txt
Execute the rewrite:run goal to apply changes in-place or rewrite:dryRun to preview them.
```bash
mvn rewrite:run
```
```bash
mvn rewrite:dryRun
```
--------------------------------
### Migrate to Spring Framework 7.0
Source: https://context7.com/openrewrite/rewrite-spring/llms.txt
Chains Framework 6.2, bumps Framework to 7.0.x, runs JUnit 5→6 migration, upgrades Jackson to 2.3, upgrades Spring Kafka to 4.0, and migrates Spring Framework nullability annotations to JSpecify equivalents.
```yaml
# rewrite.yml
---
type: specs.openrewrite.org/v1beta/recipe
name: com.example.Framework7
recipeList:
- org.openrewrite.java.spring.framework.UpgradeSpringFramework_7_0
```
```java
// Before: Spring Framework nullability annotation
import org.springframework.lang.Nullable;
public String process(@Nullable String input) { ... }
// After: migrated to JSpecify
import org.jspecify.annotations.Nullable;
public String process(@Nullable String input) { ... }
```
--------------------------------
### Migrate AutoConfiguration from spring.factories to AutoConfiguration.imports
Source: https://context7.com/openrewrite/rewrite-spring/llms.txt
Migrates @EnableAutoConfiguration entries from META-INF/spring.factories to META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports. Adds @AutoConfiguration to classes and optionally removes the old entry.
```java
import org.openrewrite.java.spring.boot2.MoveAutoConfigurationToImportsFile;
// preserveFactoriesFile=false removes the old entry from spring.factories
MoveAutoConfigurationToImportsFile recipe =
new MoveAutoConfigurationToImportsFile(false);
```
```properties
# Before: META-INF/spring.factories
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.example.FooAutoConfiguration,\
com.example.BarAutoConfiguration
# After: META-INF/spring.factories (entry removed)
# (file deleted or entry stripped)
```
```text
# Created: META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
com.example.BarAutoConfiguration
com.example.FooAutoConfiguration
```
```java
// Before
@Configuration
public class FooAutoConfiguration { }
// After
@AutoConfiguration
public class FooAutoConfiguration { }
```
--------------------------------
### Configure OpenRewrite Gradle Plugin
Source: https://context7.com/openrewrite/rewrite-spring/llms.txt
Apply the rewrite Gradle plugin in your build.gradle.kts file and configure active recipes and dependencies.
```kotlin
plugins {
id("org.openrewrite.rewrite") version "6.x"
}
rewrite {
activeRecipe("org.openrewrite.java.spring.boot3.UpgradeSpringBoot_3_5")
}
dependencies {
rewrite("org.openrewrite.recipe:rewrite-spring:5.x")
}
```
--------------------------------
### Standalone Spring Boot 3.5 Upgrade Recipe
Source: https://context7.com/openrewrite/rewrite-spring/llms.txt
Define a standalone rewrite.yml configuration file to apply the UpgradeSpringBoot_3_5 recipe.
```yaml
---
type: specs.openrewrite.org/v1beta/recipe
name: com.example.UpgradeTo35
recipeList:
- org.openrewrite.java.spring.boot3.UpgradeSpringBoot_3_5
```
--------------------------------
### Configure OpenRewrite Maven Plugin
Source: https://context7.com/openrewrite/rewrite-spring/llms.txt
Add the rewrite-maven-plugin to your pom.xml to apply recipes. Specify active recipes and include rewrite-spring as a dependency.
```xml
org.openrewrite.maven
rewrite-maven-plugin
5.x
org.openrewrite.java.spring.boot3.UpgradeSpringBoot_3_5
org.openrewrite.recipe
rewrite-spring
5.x
```
--------------------------------
### Standalone Spring Boot 4.0 Upgrade Recipe
Source: https://context7.com/openrewrite/rewrite-spring/llms.txt
Define a standalone rewrite.yml configuration file to apply the UpgradeSpringBoot_4_0 recipe.
```yaml
# rewrite.yml
---
type: specs.openrewrite.org/v1beta/recipe
name: com.example.UpgradeTo40
recipeList:
- org.openrewrite.java.spring.boot4.UpgradeSpringBoot_4_0
```
--------------------------------
### Replace String Literals with Spring HTTP Constants
Source: https://context7.com/openrewrite/rewrite-spring/llms.txt
Illustrates replacing hardcoded string literals for HTTP headers and media types with Spring's predefined constants, improving maintainability and reducing errors.
```java
// Before: String literal in controller
@GetMapping("/data")
public ResponseEntity data() {
return ResponseEntity.ok()
.header("Content-Type", "application/json")
.build();
}
// After: Spring constant used
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
@GetMapping("/data")
public ResponseEntity data() {
return ResponseEntity.ok()
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.build();
}
```
--------------------------------
### Migrate JobBuilderFactory to JobBuilder (Spring Batch 5)
Source: https://context7.com/openrewrite/rewrite-spring/llms.txt
Replaces `jobBuilderFactory.get(name)` with `new JobBuilder(name, jobRepository)`. Ensures `JobRepository` is injected if missing and removes unused fields/imports.
```java
// Before
@Configuration
public class BatchConfig {
@Autowired
private JobBuilderFactory jobBuilderFactory;
@Bean
public Job importJob(Step step) {
return jobBuilderFactory.get("importJob")
.start(step)
.build();
}
}
```
```java
// After
@Configuration
public class BatchConfig {
@Bean
public Job importJob(JobRepository jobRepository, Step step) {
return new JobBuilder("importJob", jobRepository)
.start(step)
.build();
}
}
```
--------------------------------
### Apply Spring Boot 2.x Best Practices
Source: https://context7.com/openrewrite/rewrite-spring/llms.txt
This recipe refactors controller methods to use specific HTTP method annotations like @GetMapping, removes redundant annotations, and adds @Configuration where necessary. It's useful for modernizing older Spring Boot 2.x applications.
```yaml
---
type: specs.openrewrite.org/v1beta/recipe
name: com.example.Boot2BestPractices
recipeList:
- org.openrewrite.java.spring.boot2.SpringBoot2BestPractices
```
--------------------------------
### Apply Spring Boot 3.x Best Practices (No Version Upgrade)
Source: https://context7.com/openrewrite/rewrite-spring/llms.txt
This recipe enforces Spring Boot 3.x conventions such as kebab-case property normalization, package-private @Bean methods, and precise bean return types, without performing a version upgrade. It's suitable for aligning applications with newer Spring Boot standards.
```yaml
---
type: specs.openrewrite.org/v1beta/recipe
name: com.example.Boot3BestPractices
recipeList:
- org.openrewrite.java.spring.boot3.SpringBoot3BestPracticesOnly
```
--------------------------------
### Normalize Application Properties to Kebab-Case
Source: https://context7.com/openrewrite/rewrite-spring/llms.txt
Shows the conversion of Spring Boot application properties from camelCase to kebab-case, a standard practice in Spring Boot 3.x.
```properties
# Before: application.properties
spring.datasource.maximumPoolSize=10
spring.datasource.connectionTimeout=30000
# After: kebab-case applied
spring.datasource.maximum-pool-size=10
spring.datasource.connection-timeout=30000
```
--------------------------------
### Migrate to Spring Security 6.0
Source: https://context7.com/openrewrite/rewrite-spring/llms.txt
Chains Security 5.8 migration, bumps dependency to 6.0.x, enforces SHA-256 in RememberMe, requires explicit saving of the security context repository, updates `RequestCache` usage, and removes obsolete XML attributes.
```yaml
# rewrite.yml
---
type: specs.openrewrite.org/v1beta/recipe
name: com.example.Security6
recipeList:
- org.openrewrite.java.spring.security6.UpgradeSpringSecurity_6_0
```
```xml
...
...
```
--------------------------------
### Refactor RequestMapping to GetMapping in Spring Boot 2.x
Source: https://context7.com/openrewrite/rewrite-spring/llms.txt
Demonstrates the transformation of a controller method using @RequestMapping with RequestMethod.GET to the more specific @GetMapping annotation.
```java
// Before
@Controller
@RequestMapping("/orders")
public class OrderController {
@RequestMapping(method = RequestMethod.GET)
public List list() { return orderService.findAll(); }
}
// After
@Controller
@RequestMapping("/orders")
public class OrderController {
@GetMapping
public List list() { return orderService.findAll(); }
}
```
--------------------------------
### Add Virtual Threads Configuration to application.yml
Source: https://context7.com/openrewrite/rewrite-spring/llms.txt
Demonstrates the addition of the `spring.threads.virtual.enabled: true` property to an application's YAML configuration file to enable virtual threads.
```yaml
# Before: application.yml (Java 21 project)
server:
port: 8080
# After
server:
port: 8080
spring:
threads:
virtual:
enabled: true
```
--------------------------------
### Migrate Spring Batch 5 to 6
Source: https://context7.com/openrewrite/rewrite-spring/llms.txt
Applies Spring Batch 4→5 migration, then Batch 6 package moves, type renames, method renames, and version bump.
```yaml
# rewrite.yml
---
type: specs.openrewrite.org/v1beta/recipe
name: com.example.Batch6Migration
recipeList:
- org.openrewrite.java.spring.batch.SpringBatch5To6Migration
```
```java
// Before
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.batch.item.ItemWriter;
// After
import org.springframework.batch.core.job.Job;
import org.springframework.batch.core.job.JobExecution;
import org.springframework.batch.core.launch.JobOperator;
import org.springframework.batch.infrastructure.item.ItemWriter;
```
--------------------------------
### Migrate to Spring Cloud 2025
Source: https://context7.com/openrewrite/rewrite-spring/llms.txt
Upgrades Spring Cloud dependencies to 4.3.x / BOM 2025.0.x, renames Gateway modules, and migrates Gateway configuration property keys.
```yaml
# rewrite.yml
---
type: specs.openrewrite.org/v1beta/recipe
name: com.example.Cloud2025
recipeList:
- org.openrewrite.java.spring.cloud2025.UpgradeSpringCloud_2025
```
```yaml
# Before: application.yml
spring:
cloud:
gateway:
routes:
- id: myRoute
uri: http://example.com
# After
spring:
cloud:
gateway:
server:
webflux:
routes:
- id: myRoute
uri: http://example.com
```
--------------------------------
### Enforce TLS for AMQP (RabbitMQ) connections
Source: https://context7.com/openrewrite/rewrite-spring/llms.txt
Rewrites `amqp://` connection strings to `amqps://`, optionally replaces non-TLS port numbers, and sets `spring.rabbitmq.ssl.enabled=true`. Works across both `.properties` and YAML configuration files.
```java
import org.openrewrite.java.spring.amqp.UseTlsAmqpConnectionString;
UseTlsAmqpConnectionString recipe = new UseTlsAmqpConnectionString(
"spring.rabbitmq.addresses", // property key to scan
5672, // old non-TLS port
5671, // new TLS port
"spring.rabbitmq.ssl.enabled",
null
);
```
```yaml
# Before: application.yml
spring:
rabbitmq:
addresses: amqp://rabbit.example.com:5672
# After
spring:
rabbitmq:
addresses: amqps://rabbit.example.com:5671
ssl:
enabled: true
```
--------------------------------
### Migrate to Spring Data 3.0
Source: https://context7.com/openrewrite/rewrite-spring/llms.txt
This recipe upgrades Spring Data dependencies to version 3.0.x and addresses breaking changes, such as the modification of the PagingAndSortingRepository hierarchy. It ensures compatibility with the latest Spring Data release.
```yaml
---
type: specs.openrewrite.org/v1beta/recipe
name: com.example.SpringData3
recipeList:
- org.openrewrite.java.spring.data.UpgradeSpringData_3_0
```
--------------------------------
### Update PagingAndSortingRepository for Spring Data 3.0
Source: https://context7.com/openrewrite/rewrite-spring/llms.txt
Shows how to adjust repository interfaces to accommodate the changes in Spring Data 3.0, where PagingAndSortingRepository no longer extends CrudRepository. Explicitly extending CrudRepository is necessary to retain CRUD methods.
```java
// Before: repository that relied on PagingAndSortingRepository extending CrudRepository
public interface ProductRepository
extends PagingAndSortingRepository {
// findById, save, etc. were inherited from CrudRepository
}
// After: explicitly extends CrudRepository to preserve CRUD methods
public interface ProductRepository
extends PagingAndSortingRepository,
CrudRepository {
}
```
--------------------------------
### Add Spring Property to application.properties or application.yml
Source: https://context7.com/openrewrite/rewrite-spring/llms.txt
Adds a key-value pair to Spring configuration files if it doesn't exist. Supports optional comments and glob-based file targeting.
```java
import org.openrewrite.java.spring.AddSpringProperty;
AddSpringProperty recipe = new AddSpringProperty(
"spring.threads.virtual.enabled", // property key
"true", // value
"Enable virtual threads on Java 21",// optional comment
List.of("**/application.yml") // optional path matchers
);
```
```yaml
# Before: application.yml
spring:
datasource:
url: jdbc:postgresql://localhost/mydb
# After: application.yml (property inserted)
spring:
datasource:
url: jdbc:postgresql://localhost/mydb
threads:
virtual:
# Enable virtual threads on Java 21
enabled: true
```
```properties
# Before: application.properties
spring.datasource.url=jdbc:postgresql://localhost/mydb
# After: application.properties
spring.datasource.url=jdbc:postgresql://localhost/mydb
spring.threads.virtual.enabled=true
```
--------------------------------
### Enable Virtual Threads in Spring Boot 3.x on Java 21+
Source: https://context7.com/openrewrite/rewrite-spring/llms.txt
This recipe configures Spring Boot to use virtual threads by setting `spring.threads.virtual.enabled=true`. It requires the project to be running on Java 21 or later.
```yaml
---
type: specs.openrewrite.org/v1beta/recipe
name: com.example.VirtualThreads
recipeList:
- org.openrewrite.java.spring.boot3.EnableVirtualThreads
```
--------------------------------
### Rename Spring Property Key
Source: https://context7.com/openrewrite/rewrite-spring/llms.txt
Renames a configuration key across properties, YAML, and Java annotations. Use null for exclusions.
```java
import org.openrewrite.java.spring.ChangeSpringPropertyKey;
ChangeSpringPropertyKey recipe = new ChangeSpringPropertyKey(
"server.max-http-header-size", // old key
"server.max-http-request-header-size", // new key
null // no exclusions
);
```
```yaml
# Before: application.yml
server:
max-http-header-size: 8KB
# After
server:
max-http-request-header-size: 8KB
```
```java
// Before: Java source
@Value("${server.max-http-header-size}")
private String maxHeaderSize;
// After
@Value("${server.max-http-request-header-size}")
private String maxHeaderSize;
```
--------------------------------
### Remove Redundant @Autowired on Single Constructor
Source: https://context7.com/openrewrite/rewrite-spring/llms.txt
Removes @Autowired from a class's sole constructor when Spring can infer injection. Skips classes with multiple constructors, Lombok annotations, or @ConfigurationProperties.
```java
// Before
import org.springframework.beans.factory.annotation.Autowired;
@Service
public class OrderService {
private final OrderRepository repo;
@Autowired // ← removed by recipe
public OrderService(OrderRepository repo) {
this.repo = repo;
}
}
// After
@Service
public class OrderService {
private final OrderRepository repo;
public OrderService(OrderRepository repo) {
this.repo = repo;
}
}
```
```yaml
# Run via rewrite.yml
---
type: specs.openrewrite.org/v1beta/recipe
name: com.example.CleanAnnotations
recipeList:
- org.openrewrite.java.spring.NoAutowiredOnConstructor
```
--------------------------------
### Remove Redundant @ExtendWith(SpringExtension.class)
Source: https://context7.com/openrewrite/rewrite-spring/llms.txt
Removes explicit @ExtendWith(SpringExtension.class) from tests when using Spring Boot 2.1+ and @SpringBootTest or test-slice annotations, as it's included by default.
```java
// Before
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.boot.test.context.SpringBootTest;
@ExtendWith(SpringExtension.class) // ← removed
@SpringBootTest
class ApplicationTests { }
// After
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class ApplicationTests { }
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.