Moderne OnlyThis recipe is proprietary to Moderne and runs on the Moderne platform or CLI — it isn’t part of the open-source catalog. Available with a Moderne subscription.
Migrate Dropwizard to Spring Boot 3
Recipe ID
io.moderne.java.dropwizard.boot.MigrateDropwizardToSpringBoot3Artifact
io.moderne.recipe:rewrite-dropwizardDefinition
Recipes80
80 recipes
- Migrate to Dropwizard 5.0.x from 4.x
- Change Maven managed dependency groupId, artifactId and optionally the version
- Change Gradle or Maven dependency
- Add Gradle or Maven dependency
- Add Gradle or Maven dependency
- Add Gradle or Maven dependency
- Add Gradle or Maven dependency
- Add Gradle or Maven dependency
- Add Gradle or Maven dependency
- Add Gradle or Maven dependency
- Add Gradle or Maven dependency
- Remove a Gradle or Maven dependency
- Add annotation if target supertype exists
- Remove supertype by fully qualified name
- Migrate Dropwizard
MultiPartBundleto Spring multipart configuration - Add annotation if target supertype exists
- Add annotation if target supertype exists
- Add annotation if target supertype exists
- Add annotation if target annotation exists
- Remove supertype by fully qualified name
- Change annotation attribute name
- Remove annotation attribute
- Remove annotation attribute
- Change type
- Add annotation if target supertype exists
- Add annotation if target supertype exists
- Remove a Gradle or Maven dependency
- Remove a Gradle or Maven dependency
- Add annotation if target annotation exists
- Change type
- Change type
- JUnit Jupiter migration from JUnit 4.x
- Replace Dropwizard rules with Spring Boot test configuration
- Convert Dropwizard test rule calls to RestTemplate
- Convert Mockito mock() to @MockBean
- Inline lambda body from matched method invocations
- Add
@SpringBootTestto classes usingDropwizardAppExtension - Replace a method invocation with a reference to an annotated field
- Replace a method invocation with a reference to an annotated field
- Replace
DropwizardAppExtension.getConfiguration()with@Autowiredconfiguration field - Replace
DropwizardAppExtension.getApplication()with@Autowiredapplication field - Remove class variables matching package filter
- Change supertype
- Remove supertype by fully qualified name
- Add annotation if target supertype exists
- Add lifecycle annotations to Dropwizard Managed methods
- Remove elements from a method declaration
throwsclause - Remove elements from a method declaration
throwsclause - Remove supertype by fully qualified name
- Add annotation if target supertype exists
- Migrate Dropwizard health check Result calls and wrap exceptions
- Change method access level
- Remove elements from a method declaration
throwsclause - Change method name
- Transform classes that extend a given Class to implement the given Interface instead
- Change type
- Change property key
- Change property key
- Change property key
- Change property key
- Comment out property
- Comment out property
- Comment out property
- Comment out property
- Comment out property
- Comment out property
- Comment out property
- Comment out property
- Change type
- Replace DataSourceFactory build chain with @Autowired DataSource
- Remove Dropwizard lifecycle.manage() calls
- Remove methods referencing specified package
- Remove class variables matching package filter
- Add Gradle or Maven dependency
- Change type
- Remove class variables matching package filter
- Replace
Jackson.newObjectMapper()withnew ObjectMapper().findAndRegisterModules() - Remove unnecessary
@Overrideannotations - Remove unused imports
- Add Gradle or Maven dependency
Examples
java
- java
- Diff
Before
package com.example;
import io.dropwizard.core.Configuration;
import io.dropwizard.testing.junit5.DropwizardAppExtension;
abstract class AbstractComponentTest {
static final DropwizardAppExtension<Configuration> DROPWIZARD =
new DropwizardAppExtension<>(TestApp.class, "server.yml");
void someTest() {
int port = DROPWIZARD.getLocalPort();
Object ctx = DROPWIZARD.getTestSupport().getEnvironment().getApplicationContext();
Object app = DROPWIZARD.getApplication();
Configuration config = DROPWIZARD.getConfiguration();
}
}
After
package com.example;
import io.dropwizard.core.Configuration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.context.ApplicationContext;
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
abstract class AbstractComponentTest {
@Autowired
TestApp application;
@Autowired
Configuration configuration;
@Autowired
ApplicationContext applicationContext;
@LocalServerPort
int localPort;
void someTest() {
int port = localPort;
Object ctx = applicationContext;
Object app = application;
Configuration config = configuration;
}
}
@@ -3,1 +3,4 @@
package com.example;
import io.dropwizard.core.Configuration;
-import io.dropwizard.testing.junit5.DropwizardAppExtension;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.web.server.LocalServerPort;
+import org.springframework.context.ApplicationContext;
@@ -5,0 +8,1 @@
import io.dropwizard.testing.junit5.DropwizardAppExtension;
+@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
abstract class AbstractComponentTest {
@@ -6,2 +10,8 @@
abstract class AbstractComponentTest {
- static final DropwizardAppExtension<Configuration> DROPWIZARD =
- new DropwizardAppExtension<>(TestApp.class, "server.yml");
+ @Autowired
+ TestApp application;
+ @Autowired
+ Configuration configuration;
+ @Autowired
+ ApplicationContext applicationContext;
+ @LocalServerPort
+ int localPort;
@@ -10,4 +20,4 @@
void someTest() {
- int port = DROPWIZARD.getLocalPort();
- Object ctx = DROPWIZARD.getTestSupport().getEnvironment().getApplicationContext();
- Object app = DROPWIZARD.getApplication();
- Configuration config = DROPWIZARD.getConfiguration();
+ int port = localPort;
+ Object ctx = applicationContext;
+ Object app = application;
+ Configuration config = configuration;
}
Example 2
Unchanged
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>my-app</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-dependencies</artifactId>
<version>4.0.10</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-core</artifactId>
</dependency>
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-hibernate</artifactId>
</dependency>
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-db</artifactId>
</dependency>
</dependencies>
</project>
java
- java
- Diff
Before
package com.example;
import com.codahale.metrics.health.HealthCheck;
public class MyHealthCheck extends HealthCheck {
@Override
protected HealthCheck.Result check() {
return Result.healthy();
}
}
After
package com.example;
import org.springframework.boot.actuate.health.Health;
import org.springframework.stereotype.Component;
@Component
public class MyHealthCheck implements HealthIndicator {
public Health health() {
return Health.up().build();
}
}
@@ -3,1 +3,2 @@
package com.example;
-import com.codahale.metrics.health.HealthCheck;
+import org.springframework.boot.actuate.health.Health;
+import org.springframework.stereotype.Component;
@@ -5,4 +6,4 @@
import com.codahale.metrics.health.HealthCheck;
-public class MyHealthCheck extends HealthCheck {
- @Override
- protected HealthCheck.Result check() {
- return Result.healthy();
+@Component
+public class MyHealthCheck implements HealthIndicator {
+ public Health health() {
+ return Health.up().build();
}
java
- java
- Diff
Before
package com.example;
import io.dropwizard.lifecycle.Managed;
public class MyService implements Managed {
@Override
public void start() throws Exception {
// initialize
}
@Override
public void stop() throws Exception {
// cleanup
}
}
After
package com.example;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import org.springframework.stereotype.Component;
@Component
public class MyService {
@PostConstruct
public void start() {
// initialize
}
@PreDestroy
public void stop() {
// cleanup
}
}
@@ -3,1 +3,3 @@
package com.example;
-import io.dropwizard.lifecycle.Managed;
+import jakarta.annotation.PostConstruct;
+import jakarta.annotation.PreDestroy;
+import org.springframework.stereotype.Component;
@@ -5,3 +7,4 @@
import io.dropwizard.lifecycle.Managed;
-public class MyService implements Managed {
- @Override
- public void start() throws Exception {
+@Component
+public class MyService {
+ @PostConstruct
+ public void start() {
// initialize
@@ -11,2 +14,2 @@
}
- @Override
- public void stop() throws Exception {
+ @PreDestroy
+ public void stop() {
// cleanup
java
- java
- Diff
Before
package com.example;
import io.dropwizard.core.Configuration;
import io.dropwizard.testing.junit5.DropwizardAppExtension;
abstract class AbstractComponentTest {
static final DropwizardAppExtension<Configuration> DROPWIZARD =
new DropwizardAppExtension<>(TestApp.class, "server.yml");
void someTest() {
int port = DROPWIZARD.getLocalPort();
Object ctx = DROPWIZARD.getTestSupport().getEnvironment().getApplicationContext();
Object app = DROPWIZARD.getApplication();
Configuration config = DROPWIZARD.getConfiguration();
}
}
After
package com.example;
import io.dropwizard.core.Configuration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.context.ApplicationContext;
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
abstract class AbstractComponentTest {
@Autowired
TestApp application;
@Autowired
Configuration configuration;
@Autowired
ApplicationContext applicationContext;
@LocalServerPort
int localPort;
void someTest() {
int port = localPort;
Object ctx = applicationContext;
Object app = application;
Configuration config = configuration;
}
}
@@ -3,1 +3,4 @@
package com.example;
import io.dropwizard.core.Configuration;
-import io.dropwizard.testing.junit5.DropwizardAppExtension;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.web.server.LocalServerPort;
+import org.springframework.context.ApplicationContext;
@@ -5,0 +8,1 @@
import io.dropwizard.testing.junit5.DropwizardAppExtension;
+@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
abstract class AbstractComponentTest {
@@ -6,2 +10,8 @@
abstract class AbstractComponentTest {
- static final DropwizardAppExtension<Configuration> DROPWIZARD =
- new DropwizardAppExtension<>(TestApp.class, "server.yml");
+ @Autowired
+ TestApp application;
+ @Autowired
+ Configuration configuration;
+ @Autowired
+ ApplicationContext applicationContext;
+ @LocalServerPort
+ int localPort;
@@ -10,4 +20,4 @@
void someTest() {
- int port = DROPWIZARD.getLocalPort();
- Object ctx = DROPWIZARD.getTestSupport().getEnvironment().getApplicationContext();
- Object app = DROPWIZARD.getApplication();
- Configuration config = DROPWIZARD.getConfiguration();
+ int port = localPort;
+ Object ctx = applicationContext;
+ Object app = application;
+ Configuration config = configuration;
}
Example 6
Unchanged
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>my-app</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-dependencies</artifactId>
<version>4.0.10</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-core</artifactId>
</dependency>
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-hibernate</artifactId>
</dependency>
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-db</artifactId>
</dependency>
</dependencies>
</project>
java
- java
- Diff
Before
package com.example;
import com.codahale.metrics.health.HealthCheck;
public class MyHealthCheck extends HealthCheck {
@Override
protected HealthCheck.Result check() {
return Result.healthy();
}
}
After
package com.example;
import org.springframework.boot.actuate.health.Health;
import org.springframework.stereotype.Component;
@Component
public class MyHealthCheck implements HealthIndicator {
public Health health() {
return Health.up().build();
}
}
@@ -3,1 +3,2 @@
package com.example;
-import com.codahale.metrics.health.HealthCheck;
+import org.springframework.boot.actuate.health.Health;
+import org.springframework.stereotype.Component;
@@ -5,4 +6,4 @@
import com.codahale.metrics.health.HealthCheck;
-public class MyHealthCheck extends HealthCheck {
- @Override
- protected HealthCheck.Result check() {
- return Result.healthy();
+@Component
+public class MyHealthCheck implements HealthIndicator {
+ public Health health() {
+ return Health.up().build();
}
java
- java
- Diff
Before
package com.example;
import io.dropwizard.lifecycle.Managed;
public class MyService implements Managed {
@Override
public void start() throws Exception {
// initialize
}
@Override
public void stop() throws Exception {
// cleanup
}
}
After
package com.example;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import org.springframework.stereotype.Component;
@Component
public class MyService {
@PostConstruct
public void start() {
// initialize
}
@PreDestroy
public void stop() {
// cleanup
}
}
@@ -3,1 +3,3 @@
package com.example;
-import io.dropwizard.lifecycle.Managed;
+import jakarta.annotation.PostConstruct;
+import jakarta.annotation.PreDestroy;
+import org.springframework.stereotype.Component;
@@ -5,3 +7,4 @@
import io.dropwizard.lifecycle.Managed;
-public class MyService implements Managed {
- @Override
- public void start() throws Exception {
+@Component
+public class MyService {
+ @PostConstruct
+ public void start() {
// initialize
@@ -11,2 +14,2 @@
}
- @Override
- public void stop() throws Exception {
+ @PreDestroy
+ public void stop() {
// cleanup
Usage
Run this recipe
This recipe has no required configuration options. Users of Moderne can run it via the Moderne CLI.
You will need to have configured the Moderne CLI on your machine before you can run the following command.
shell
mod run . --recipe MigrateDropwizardToSpringBoot3
If the recipe is not available locally, then you can install it using:
mod config recipes jar install io.moderne.recipe:rewrite-dropwizard:0.5.1
Data tables
Maven metadata failures
org.openrewrite.maven.table.MavenMetadataFailuresAttempts to resolve maven metadata that failed.
| Column | Description |
|---|---|
| Group id | The groupId of the artifact for which the metadata download failed. |
| Artifact id | The artifactId of the artifact for which the metadata download failed. |
| Version | The version of the artifact for which the metadata download failed. |
| Maven repository | The URL of the Maven repository that the metadata download failed on. |
| Snapshots | Does the repository support snapshots. |
| Releases | Does the repository support releases. |
| Failure | The reason the metadata download failed. |
Source files that had results
org.openrewrite.table.SourcesFileResultsSource files that were modified by the recipe run.
| Column | Description |
|---|---|
| Source path before the run | The source path of the file before the run. null when a source file was created during the run. |
| Source path after the run | A recipe may modify the source path. This is the path after the run. null when a source file was deleted during the run. |
| Parent of the recipe that made changes | In a hierarchical recipe, the parent of the recipe that made a change. Empty if this is the root of a hierarchy or if the recipe is not hierarchical at all. |
| Recipe that made changes | The specific recipe that made a change. |
| Estimated time saving | An estimated effort that a developer to fix manually instead of using this recipe, in unit of seconds. |
| Cycle | The recipe cycle in which the change was made. |
Source files that had search results
org.openrewrite.table.SearchResultsSearch results that were found during the recipe run.
| Column | Description |
|---|---|
| Source path of search result before the run | The source path of the file with the search result markers present. |
| Source path of search result after run the run | A recipe may modify the source path. This is the path after the run. null when a source file was deleted during the run. |
| Result | The trimmed printed tree of the LST element that the marker is attached to. |
| Description | The content of the description of the marker. |
| Recipe that added the search marker | The specific recipe that added the Search marker. |
Source files that errored on a recipe
org.openrewrite.table.SourcesFileErrorsThe details of all errors produced by a recipe run.
| Column | Description |
|---|---|
| Source path | The file that failed to parse. |
| Recipe that made changes | The specific recipe that made a change. |
| Stack trace | The stack trace of the failure. |
Recipe performance
org.openrewrite.table.RecipeRunStatsStatistics used in analyzing the performance of recipes.
| Column | Description |
|---|---|
| The recipe | The recipe whose stats are being measured both individually and cumulatively. |
| Source file count | The number of source files the recipe ran over. |
| Source file changed count | The number of source files which were changed in the recipe run. Includes files created, deleted, and edited. |
| Cumulative scanning time (ns) | The total time spent across the scanning phase of this recipe. |
| Max scanning time (ns) | The max time scanning any one source file. |
| Cumulative edit time (ns) | The total time spent across the editing phase of this recipe. |
| Max edit time (ns) | The max time editing any one source file. |