Skip to main content

Migrate Dropwizard to Spring Boot 3

io.moderne.java.dropwizard.boot.MigrateDropwizardToSpringBoot3

Migrate a Dropwizard application to Spring Boot 3. First applies the Dropwizard to Spring Boot 2.7 migration, then adds managed lifecycle and health check migrations on top.

Recipe source

This recipe is only available to users of Moderne.

This recipe is available under the Moderne Proprietary License.

Examples

Example 1

DropwizardAppExtensionJUnit5MigrationIntegrationTest#migratesCustomerExample

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;
}
}

Example 2

MigrateDropwizardToSpringBoot3Test#migratesDependencies

Unchanged
pom.xml
<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>

Example 3

MigrateHealthCheckMethodTest#migratesCheckMethodSignature

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();
}
}

Example 4

MigrateManagedLifecycleTest#migratesManagedStartStop

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
}
}

Example 5

DropwizardAppExtensionJUnit5MigrationIntegrationTest#migratesCustomerExample

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;
}
}

Example 6

MigrateDropwizardToSpringBoot3Test#migratesDependencies

Unchanged
pom.xml
<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>

Example 7

MigrateHealthCheckMethodTest#migratesCheckMethodSignature

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();
}
}

Example 8

MigrateManagedLifecycleTest#migratesManagedStartStop

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
}
}

Usage

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.4.0

See how this recipe works across multiple open-source repositories

Run this recipe on OSS repos at scale with the Moderne SaaS.

The community edition of the Moderne platform enables you to easily run recipes across thousands of open-source repositories.

Please contact Moderne for more information about safely running the recipes on your own codebase in a private SaaS.

Data Tables

Maven metadata failures

org.openrewrite.maven.table.MavenMetadataFailures

Attempts to resolve maven metadata that failed.

Column NameDescription
Group idThe groupId of the artifact for which the metadata download failed.
Artifact idThe artifactId of the artifact for which the metadata download failed.
VersionThe version of the artifact for which the metadata download failed.
Maven repositoryThe URL of the Maven repository that the metadata download failed on.
SnapshotsDoes the repository support snapshots.
ReleasesDoes the repository support releases.
FailureThe reason the metadata download failed.